before_filter with devise
我正在使用Devise内置的before_filter :authenticate_user!
。 如果用户未通过filter(尝试在注销时执行操作),我想在我的应用程序助手中调用我自己的自定义方法。 我该怎么做?
我会在使用user_signed_in?
filter之前编写一个自定义user_signed_in?
。 这只会返回一个布尔值,而不会执行authenticate_user!
任何重定向类型操作authenticate_user!
确实。
所以,你可以像这样编写一个之前的filter:
before_filter :custom_user_auth ... def custom_user_auth unless user_signed_in? # Do custom stuff, ultimately restricting access to the # ...protected resource if it needs to be end end
请注意,此filter之前不会保护您的资源免受未经授权的用户的攻击, unless
声明的内部区域重定向或呈现。
而不是调用before_filter :authenticate_user!
在你的调用authenticate_user!
的控制器中编写自己的函数authenticate_user!
。 就像是:
before_filter :logged_in ... private def logged_in your_function authenticate_user! end
- 用于Rails的Mailchimp API – list.subscribe(:double_optin => false)无法正常工作
- 如何在自定义capistrano任务中使用事务?
- rake db:migrate生成“rake aborted! 找不到表“错误
- 如何在Cloud9上访问localhost:1080
- Rails:无法加载UTF8Handler的Unicode表
- 为memcached和Rails组合片段和对象缓存的最佳方法
- 蓝图css中的资产预编译错误 – ActionView :: Template :: Error(blueprint / screen.css未预编译) – 内部服务器错误500
- 我可以在Ruby on Rails上编写PostgreSQL函数吗?
- 是否有Rails Gem Devise的解决方案允许用户拥有多封电子邮件?