我正在创建一个包含设计的 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/