【发布时间】:2017-05-07 01:54:24
【问题描述】:
我正在创建一个包含 devise 的 rails 应用程序。 我正在尝试使用 Ngrok 将 Twilio 消息添加到我的网站,我使用了本教程: https://www.twilio.com/blog/2016/04/receive-and-reply-to-sms-in-rails.html
我能够在控制台中打开 Ngrok 并获取他们为我的 url 提供的 web-id。 当我将 url 插入浏览器时,我不断收到此错误。我应该访问我自己的 rails 本地应用程序。不知道出了什么问题。
我在为 ngrok 制作的消息控制器中添加的内容:
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 应该由 devise 定义。
【问题讨论】:
-
你的意思是什么错误?有堆栈跟踪吗?
-
错误是“ArgumentError in MessagesController#reply”“在 process_action 回调之前:authenticate_user!尚未定义”
-
并突出显示“skip_before_filter :authenticate_user!, :only => "reply"" 行
-
当我删除该行时,我收到此错误:“MessagesController#reply 中的 NameError”...“未初始化的常量 MessagesController::Twilio”。这突出了代码``` @client = Twilio::REST::Client.new account_sid, auth_token```
-
好的,仍在检查您的第一个错误,但第二个错误听起来您还没有安装 Twilio gem。将
gem 'twilio-ruby'添加到您的 Gemfile,运行bundle install并再试一次。
标签: ruby-on-rails ruby devise twilio ngrok