如何避免sendgrid覆盖我的类? [重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我刚刚使用了将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
ruby-on-rails sendgrid
1个回答
3
投票
include SendGrid

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

在你的辩护中,这条线确实存在于SendGrid's quick start snippets,但我不知道该为什么。看起来未使用sendgrid类的每个用法都是命名空间。所以,是的,只需删除它,你应该是好的。

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

© www.soinside.com 2019 - 2024. All rights reserved.