为清楚起见,简化了名称和对象.基本概念保持不变.
我有三个控制器:dog,cat,和horse.这些控制器都继承自控制器animal.在控制器中animal,我有一个before过滤器,用于对用户进行身份验证:
before_filter :authenticate
def authenticate
authenticate_or_request_with_http_basic do |name, password|
name == "foo" && password == "bar"
end
end
Run Code Online (Sandbox Code Playgroud)
在show行动中dog,我需要对所有用户具有开放访问权限(跳过身份验证).
如果我要单独编写身份验证dog,我可以这样做:
before_filter :authenticate, :except => :show
Run Code Online (Sandbox Code Playgroud)
但是由于dog继承自animal,我无法访问特定于控制器的操作.添加:except => :show在animal控制器不仅将跳过认证show的作用dog,也表明中cat和horse.不希望出现这种情况.
如何才能跳过身份验证仅针对仍然继承的show操作?doganimal
嘿,伙计们.所以我想到了这个酷炫的想法,如果你登录然后你得到某种仪表板,否则你得到一个信息/登录/注册页面..所以我该怎么做..
我主要想在Routes中这样做=不是这样的
def index
if current_user.present?
render :action => 'logged_in'
else
render :action => 'logged_out'
end
end
Run Code Online (Sandbox Code Playgroud)
提前致谢!
/ Oluf Nielsen