[英]Devise custom layout
I need some help here. 我需要一些帮助。
I'm using the Devise gem for authentication and I've set up my routes as follow 我正在使用Devise gem进行身份验证,并且按照以下步骤设置了路由
Rails.application.routes.draw do
devise_for :users, path: '', path_names: { sign_in: 'login', sign_out: 'logout', sign_up: 'join', password: 'forgot-password', edit: 'settings'}
root to: 'pages#index'
end
I am then using a different layout file for all devise views 然后,我对所有设计视图使用不同的布局文件
class ApplicationController < ActionController::Base
layout :layout_by_resource
private
def layout_by_resource
if devise_controller? && resource_name == :user
"devise_custom"
else
"application"
end
end
end
This works fine but I would like to make an exception for devise users/edit. 这工作正常,但我想为设计用户/编辑设置例外。 So that the registrations edit action uses the application layout instead. 这样,注册编辑操作将使用应用程序布局。
Please anyone, how can I achieve this? 请任何人,我该如何实现?
Thanks in advance! 提前致谢!
/ Jacob /雅各布
According with this section , you can do something like this 根据本节的内容 ,您可以执行以下操作
class ApplicationController < ActionController::Base
# Layout per resource_name
def layout_by_resource
if devise_controller? && resource_name == :admin
"layout_name_for_devise_admin"
else
"application"
end
end
# Layout per resource_name AND action
def layout_by_resource
if devise_controller? && resource_name == :user && action_name == "new"
"layout_name_for_devise"
else
"application"
end
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.