首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何避免sendgrid覆盖我的类?

如何避免sendgrid覆盖我的类?
EN

Stack Overflow用户
提问于 2019-04-08 14:12:13
回答 1查看 47关注 0票数 0

我刚刚使用

代码语言:javascript
复制
gem 'sendgrid-ruby'

因此,我开始有问题,我的课程加载。问题是,我已经有了一个叫做client.rb的模型

代码语言:javascript
复制
class Client < ApplicationRecord
  belongs_to :user

因此,有时CanCanCan或其他方法会被Sendgrid客户端类覆盖。例如,在这里:

代码语言:javascript
复制
if user.talent.present?
  # Talents can only read his own booking model
  can [:read, :accept, :check_in, :update], Booking, { talent: { user_id: user.id } }

  # Talents can only see his own connections
  can :read, Connection, Connection.where('user_1_id = :id or user_2_id  = :id', id: user.id) do |connection|
    (connection.user_1_id == user.id) || (connection.user_2_id == user.id)
  end

  can :create, Photo
  # can :read, Photo, user_id: user.id
  can :update, Photo, user_id: user.id
  can :delete, Photo, user_id: user.id

elsif user.client.present?
  can :create, Booking
  can [:read, :update], Booking, user_id: user.id
  #can :update, Booking, { talent: { user_id: user.id } }
  # Should we able to delete Bookings? or those created bookings get archive?

  # TODO: Really?
  # can :read, Agency
  # can :update, Client, user_id: user.id

在这种方法中,user.client.present?破坏应用程序,因为CanCanCan认为客户机是Sendgrid::Client的实例,而不是我自己的模型

我如何让我的应用程序一直知道“客户端”应该是我自己的类,而不是Sendgrid类呢?

我导入sendgrid的唯一要点是在我的邮箱上:

代码语言:javascript
复制
require 'sendgrid-ruby'
include SendGrid

class AdminMailer < ApplicationMailer
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-08 14:15:53

包括SendGrid

是啊那就是你的问题所在。不要这样做。

作为您的辩护,这一行在SendGrid的快速启动片段中确实存在,但我不知道这是为了什么。看上去没用过。sendgrid类的每次使用都是名称空间的。所以是的,只要把它移开,你就应该很好。

也来看看这个:https://sendgrid.com/docs/for-developers/sending-email/rubyonrails/

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55575450

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档