![](/img/trans.png)
[英]Dividing authenticated and unauthenticated layouts in Rails with Devise
[英]Rails: Multiple layouts with Devise
如何根据用户是否登录来拥有完全不同的布局?
请按照以下说明进行操作
https://github.com/plataformatec/devise/wiki/How-To%3a-Create-custom-layouts
并检查用户是否已登录,这对设计而言意味着检查
user_signed_in?
,这是一个设计助手。
特别:
class ApplicationController < ActionController::Base
layout :layout_by_resource
protected
def layout_by_resource
if user_signed_in?
"special_layout_name_for_logged_in"
else
"application"
end
end
end
并将special_layout_for_logged_in.html.erb
视图文件放在layouts目录中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.