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

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]

(编辑:李大同)

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

    推荐文章
      热点阅读