加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在process_action回调之前:authenticate_user

发布时间:2020-12-17 03:50:23 所属栏目:百科 来源:网络整理
导读:我正在创建一个包含设计的rails应用程序. 我正在尝试使用Ngrok将Twilio消息传递到我的网站,我使用了本教程: https://www.twilio.com/blog/2016/04/receive-and-reply-to-sms-in-rails.html 我能够在控制台中打开Ngrok并获取他们为我的网址提供的网络ID. 当
我正在创建一个包含设计的rails应用程序.
我正在尝试使用Ngrok将Twilio消息传递到我的网站,我使用了本教程:
https://www.twilio.com/blog/2016/04/receive-and-reply-to-sms-in-rails.html

我能够在控制台中打开Ngrok并获取他们为我的网址提供的网络ID.
当我将网址插入我的浏览器时,我不断收到此错误.我应该到我自己的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定义.

解决方法

Twilio开发者传道者在这里.

看起来这是Rails 5似乎引入的一个问题.如果过滤器尚未在控制器中使用时定义,则会引发错误. 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

如果这有帮助,请告诉我.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读