我的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 的 :landing 操作),Rails 尝试传递 require_login...
我误解了这个过滤器的某些内容,还是我有什么问题?
谢谢你的帮助!
这对我来说听起来很正常 - 你已经要求 Rails 跳过你之前的操作,除非该操作是:landing
, :connect
or :create
然而听起来你想要相反的东西。如果您希望这 3 个操作不执行require_login
那么你应该做
skip_before_action :require_login, :only => [:landing, :connect, :create]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)