我正在努力将 twilio-ruby gem 集成到我的应用程序中,但是,我遇到了这个错误:
NoMethodError in NotificationsController#notify - undefined method `secrets' for #<Medy::Application:0x007f8dfcac1048>
这是我的notifications_controller.rb
require 'twilio-ruby'
class NotificationsController < ApplicationController
skip_before_action :verify_authenticity_token
def notify
client = Twilio::REST::Client.new Rails.application.secrets.twilio_account_sid, Rails.application.secrets.twilio_auth_token
message = client.messages.create from: '+5555555555', to: '+5555555555', body: 'First ever MyMedy notifcation test.'
render plain: message.status
end
end
这是我的config/secrets.yml文件 - (我修改了这篇文章的secrets):
development:
secret_key_base: 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
twilio_account_sid: <%= ENV["AC5xxxxxxxxxxxxx"] %>
twilio_auth_token: <%= ENV["ae6xxxxxxxxxxxxxxx"] %>
test:
production:
secret_key_base: 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
twilio_account_sid: <%= ENV["AC5xxxxxxxxxxxxx"] %>
twilio_auth_token: <%= ENV["ae6xxxxxxxxxxxxxxx"] %>
我在这里遵循了 Twilio 教程,但是,我仍然收到错误。
通过更新到 Rails 4.1 然后重新启动 Rails 服务器来修复此问题。