ruby-on-rails – 行动之前的Rails跳过不起作用
发布时间:2020-12-16 19:45:14 所属栏目:百科 来源:网络整理
导读:我有一个skip_before操作的问题: class ApplicationController ActionController::Base protect_from_forgery with: :exception before_action :require_login before_action :inc_cookies def inc_cookies if cookies[:token] != nil @name = cookies[:nam
我有一个skip_before操作的问题:
class ApplicationController < ActionController::Base protect_from_forgery with: :exception before_action :require_login before_action :inc_cookies def inc_cookies if cookies[:token] != nil @name = cookies[:name] @surname = cookies[:surname] @user_roomate = cookies[:roomate] end end def require_login if cookies[:token] == nil puts "No token" redirect_to '/' end end end 和我的其他控制器: class UsersController < ApplicationController skip_before_action :require_login,:except => [:landing,:connect,:create] end 我不知道为什么,但是当我在根目录(来自UsersController的登陆操作)时,Rails尝试传入require_login … 感谢任何帮助! 解决方法
这对我来说听起来正常 – 你已经要求轨道跳过你的行动,除非是行动是:登陆,连接或:创建,而听起来好像你想要的是相反的.如果你想要这3个动作不执行require_login,那么你应该做
skip_before_action :require_login,:only => [:landing,:create] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- c# – 如何使用rowdeleting事件删除gridview中的
- 从以下代码获取警告“转换为不同大小的整数的指针
- Cocos2d-x学习(二) 在Cocos2d-x2.2.6搭建你第一
- ruby-on-rails – 像在Ruby中的条件
- reactjs – React Native(使用Redux)动画切换以编
- 吴恩达老师深度学习视频课笔记:超参数调试、Bat
- reactjs – 无法动态地在react组件中创建元素
- c# – ElementHost FlowDocument = GC不工作,内存
- 浅谈关于angularJs中使用$.ajax的注意点
- iphone – 显示alertview后如何移动到下一个视图
热点阅读