设计中 sign_in 操作的不同布局 [英] different layout for sign_in action in devise
问题描述
我正在尝试为 sign_in 操作使用名为devise"的不同/自定义布局.我在设计 wiki 中找到了 this 页面,并且第二个示例甚至说您可以按操作执行此操作(在本例中为 sign_in
操作),但没有显示执行此操作的示例.IRC 上有人告诉我我可以试试这个:
I'm trying to use a different/custom layout named "devise" for the sign_in action. I found this page in the devise wiki, and the second example even says you can do it per-action (in this case, sign_in
action), but it shows no example of doing that. Someone on IRC told me I could try this:
class ApplicationController < ActionController::Base
protect_from_forgery
layout :layout_by_resource
def layout_by_resource
if devise_controller? && resource_name == :user && action_name == 'sign_in'
"devise"
else
"application"
end
end
end
但它似乎不起作用,因为它仍在加载默认的应用程序布局.我将不胜感激.
But it does not seem to be working as it's still loading the default application layout. I would appreciate any help.
推荐答案
我想通了,但我会把这个问题留在这里以防其他人好奇.
I figured it out, but I'll keep this question here in case other people are curious.
这是一个愚蠢的错误.事实上,sign_in
是路径,不是动作.查看相关源码,可以看到所需的操作是new
,即创建一个new设计会话.将我上面代码的条件更改为:
It was a stupid mistake. The fact is sign_in
is the path, not the action. Looking at the relevant source, I can see that the required action is new
, i.e., creating a new Devise Session. Changing my above code's conditional to:
if devise_controller? && resource_name == :user && action_name == 'new'
效果很好.
希望能帮助到那里的人.
Hope that helps someone out there.
这篇关于设计中 sign_in 操作的不同布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!