Rails中只有一个特定页面的不同布局

时间:2011-02-26 15:40:46

标签: ruby-on-rails ruby-on-rails-3

我希望在我的Rails应用中只为一个特定操作设置不同的布局。我该怎么做?

3 个答案:

答案 0 :(得分:26)

# controller that calls the page
def action
  render :layout => 'other'
end

答案 1 :(得分:19)

class MyController < ApplicationController
  layout "special", :only => :action

  def action
    #action code
  end
end

答案 2 :(得分:9)

 layout :resolve_layout

  .
  .
  .
     private   
      def resolve_layout
       case action_name
         when "new"
          "alternate"
         else 
          "application"
         end
      end