ruby-on-rails - Rails : Before process_action callback :authenticate_user! 尚未定义

标签 ruby-on-rails ruby devise twilio ngrok

我正在创建一个包含设计的 Rails 应用程序。 我正在尝试使用 Ngrok 将 Twilio 消息传递添加到我的站点,我使用了本教程: https://www.twilio.com/blog/2016/04/receive-and-reply-to-sms-in-rails.html

我能够在控制台中打开 Ngrok 并获取他们为我的网址提供的网络 ID。 当我将 url 插入浏览器时,我不断收到此错误。我应该访问我自己的 Rails 本地应用程序。不知道怎么了。

我在为 ngrok 制作的消息传递 Controller 中添加的内容:

class MessagesController < ApplicationController
  skip_before_filter :verify_authenticity_token 
  skip_before_filter :authenticate_user!, :only => "reply"

def reply
   message_body = params["Body"]
   from_number = params["From"]
   boot_twilio
   sms = @client.messages.create(
     from: Rails.application.secrets.twilio_number,
     to: from_number,
     body: "Hello there, thanks for texting me. Your number is #{from_number}."
  )
  #twilio expects a HTTP response to this request
end


private
 def boot_twilio
   account_sid = Rails.application.secrets.twilio_sid
   auth_token = Rails.application.secrets.twilio_token
   @client = Twilio::REST::Client.new account_sid, auth_token
 end
end

真的不知道哪里出了问题。 当它没有连接到“def reply”时,authenticate_user 应该由设计定义。

最佳答案

此处为 Twilio 开发人员布道师。

看起来这是 Rails 5 引入的问题。如果过滤器在 Controller 中使用时尚未定义,则会引发错误。 This was discovered in the Clearance project too .

Their fix是将 raise: false 选项传递给 skip_before_filter:

class MessagesController < ApplicationController
  skip_before_filter :verify_authenticity_token 
  skip_before_filter :authenticate_user!, :only => "reply", :raise => false

end

关于ruby-on-rails - Rails : Before process_action callback :authenticate_user! 尚未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41266207/

相关文章:

ruby-on-rails - 查找带有 ID 的对象名称

ruby - 如何获取 ruby​​ 脚本中 fatal error 的确切消息

没有 Rails 的 Ruby

ruby-on-rails-4 - 使用 Rspec 测试自定义设备注册 Controller 更新操作

ruby-on-rails - rails : Using CanCan to assign multiple roles to Users for each organization they belong to?

javascript - Backbone JS Turbolinks 未定义问题

ruby - 检索 URL 的内容作为字符串

ruby-on-rails - 使用devise:omniauthable设置多个提供程序

ruby-on-rails-3 - #<ActiveRecord::ConnectionAdapters::TableDefinition:0x9dee690> 的未定义方法 `database_authenticatable'

ruby-on-rails - 如何实现像Stack Overflow一样的搜索