【发布时间】:2019-04-08 14:12:13
【问题描述】:
我刚刚使用
将 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
【问题讨论】: