2013-06-18 52 views
2
class UserSignupController < ApplicationController 

    layout "signup", only: [:signup] 
    layout "user_sessions", only: [:thanks] 

    def signup 
    end 

    def thanks 
    end 
end 

我有两种不同的布局。我想调用注册布局来注册。它可以正常工作。但是,当我给两个布局它崩溃我的代码。是否有可能这样做?如何在导轨控制器中调用多个布局

回答

2

如果您想使用单独的操作,则可以在每个操作中指定布局。因此,例如

def signup 
    render "signup", layout: "signup" 
end 

def thanks 
    render "thanks", layout: "thanks" 
end 

应该这样做:)

0

您可以添加设置布局的方法,并在私人投入。

class UserSignupController < ApplicationController 
    layout :specific_layout 

    def signup 
    end 

    def thanks 
    end 

    private 

    def specific_layout 
    case action_name 
    when "signup" 
     "signup" 
    when "thanks" 
     "user_sessions" 
    else 
     "otherlayout" 
    end 
    end 
end