2013-06-18 5 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 
관련 문제