Rails Model name conflict with included gem

前端 未结 1 1959
遇见更好的自我
遇见更好的自我 2021-01-21 15:24

We\'ve been mocking up our email jobs with success until we actually included our SendGrid Gem at the top of our worker

require \'sendgrid-ruby\'
include SendGri         


        
相关标签:
1条回答
  • 2021-01-21 16:06

    include SendGrid it the culprit.

    It adds all constants from the SendGrid module to the current module (which is probably the top level), so you can use SendGrid's classes without prefix, e.g. just Email.new instead of SendGrid::Email.new.

    The downside is that it also messes with your existing constants.

    You can either include it under a specific module:

    class Notifications::WelcomeWorker
      include Sidekiq::Worker
      include SendGrid
    
      # ...
    end
    

    Then, Email resolves to Sendgrid::Email and ::Email resolves to your top-level Email class.

    Or you could simply remove the include SendGrid line and use the SendGrid:: prefix.

    0 讨论(0)
提交回复
热议问题