我刚刚使用
将Sendgrid添加到了我的应用中gem 'sendgrid-ruby'
所以我开始在类加载方面遇到问题。问题是,我已经有一个名为client.rb
的模型class Client < ApplicationRecord
belongs_to :user
因此,有时CanCanCan或其他方法被Sendgrid客户端类覆盖。例如此处:
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认为Client是Sendgrid :: Client的实例,而不是我自己的模型
如何使我的应用程序始终知道“客户端”应该是我自己的类,而不是Sendgrid呢?
我导入sendgrid的唯一要点是我的邮件中:
require 'sendgrid-ruby'
include SendGrid
class AdminMailer < ApplicationMailer
答案 0 :(得分:3)
include SendGrid
是的,这就是您的问题所在。不要这样做。
在您的辩护中,SendGrid's quick start snippets中存在这行 ,但是我不确定该做什么。看起来没用。 sendgrid的类的每种用法都是命名空间。所以,是的,只需将其删除即可。
也来看看这个:https://sendgrid.com/docs/for-developers/sending-email/rubyonrails/