Rails:在process_action回调之前:authenticate_user!尚未定义 [英] Rails: Before process_action callback :authenticate_user! has not been defined

查看:75
本文介绍了Rails:在process_action回调之前:authenticate_user!尚未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm creating a rails app that includes devise. I'm trying to add Twilio messaging to my site with Ngrok, i used this tutorial: https://www.twilio.com/blog/2016/04/receive-and-reply-to-sms-in-rails.html

我能够在控制台中打开Ngrok并获取他们为我的URL提供的Web ID.将URL插入浏览器时,我一直收到此错误.我应该进入自己的Rails本地应用程序.不知道怎么了.

I was able to open Ngrok in the console and get the web-id they give for my url. I keep getting this error when I plug the url into my browser ..I'm supposed to get to my own rails local app. Not sure whats wrong.

我在邮件控制器中添加的用于ngrok的内容:

What I added in my messaging controller made for 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回复"和authenticate_user时,应由devise定义.

really unsure what is wrong. when its not connecting to the 'def reply' and authenticate_user should be defined by devise.

推荐答案

此处是Twilio开发人员的福音.

Twilio developer evangelist here.

Rails 5似乎引入了这个问题.如果尚未在控制器中使用过滤器时定义过滤器,则会引发错误.这也是在Clearance项目中发现的.

It looks like this was a problem that Rails 5 seems to have introduced. If the filter hasn't been defined by the time it is used in a controller it will raise an error. This was discovered in the Clearance project too.

他们的解决方法是通过 raise:false skip_before_filter 的选项:

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

end

让我知道这是否有帮助.

Let me know if that helps at all.

这篇关于Rails:在process_action回调之前:authenticate_user!尚未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆