我刚刚使用
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认为客户机是Sendgrid::Client的实例,而不是我自己的模型
我如何让我的应用程序一直知道“客户端”应该是我自己的类,而不是Sendgrid类呢?
我导入sendgrid的唯一要点是在我的邮箱上:
require 'sendgrid-ruby'
include SendGrid
class AdminMailer < ApplicationMailer发布于 2019-04-08 14:15:53
包括SendGrid
是啊那就是你的问题所在。不要这样做。
作为您的辩护,这一行在SendGrid的快速启动片段中确实存在,但我不知道这是为了什么。看上去没用过。sendgrid类的每次使用都是名称空间的。所以是的,只要把它移开,你就应该很好。
也来看看这个:https://sendgrid.com/docs/for-developers/sending-email/rubyonrails/
https://stackoverflow.com/questions/55575450
复制相似问题