0
是否可以根据整个应用中的条件呈现不同的模板?Rails渲染模板
我不希望在每个视图水木清华写这样
if domain =='cool'
render template 'cool/index'
else
regular template
end
我想我需要为它
是否可以根据整个应用中的条件呈现不同的模板?Rails渲染模板
我不希望在每个视图水木清华写这样
if domain =='cool'
render template 'cool/index'
else
regular template
end
我想我需要为它
你可以在你的ApplicationController像这样实现这一目标做application controller
东西。通过将一个符号传递给布局方法,它允许您动态地将布局分配给应用程序中的所有控制器。
class ApplicationController
layout :special_layout
private
def special_layout
(domain =='cool') ? "cool" : "not_cool"
end
end