在设计中的sign_in动作的不同布局 [英] different layout for sign_in action in devise
问题描述
我正在尝试使用名为devise的不同/自定义布局作为sign_in操作。我在设计维基中发现了这个页面,第二个例子甚至表示你可以按照每个动作(在这种情况下, sign_in
操作)来执行,但是它没有显示这样的例子。 IRC上有人告诉我可以试试这个:
class ApplicationController< ActionController :: Base
protect_from_forgery
布局:layout_by_resource
def layout_by_resource
如果devise_controller? &安培;&安培; resource_name ==:user&& action_name =='sign_in'
devise
else
应用程序
end
end
end
但它似乎没有工作,因为它仍然加载默认的应用程序布局。我会感谢任何帮助。
我想出来,但我会在这里保留这个问题,以防其他人好奇
这是一个愚蠢的错误。事实是 sign_in
是路径,不是的动作。查看相关来源,我可以看到所需的操作是 new
,即创建一个新的设计会话。更改我的上述代码条件为:
if devise_controller? &安培;&安培; resource_name ==:user&& action_name =='new'
精美地工作。
希望有帮助的人在那里。
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.
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'
Works beautifully.
Hope that helps someone out there.
这篇关于在设计中的sign_in动作的不同布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!