Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set a layout for certain actions?

My app/views/layouts folder looks like this:

application.html.erb
user_sessions.html.erb
errors.html.erb

These work fine and i have no problems with them but id now like to add a new layout for tips, but only on the index and show actions.

Would "tips.index.html.erb" work?

like image 869
Arcath Avatar asked Jan 20 '10 14:01

Arcath


2 Answers

Add a new layout as you like called 'tips.html.erb'

In the tips controller add the following:

layout "tips", :only => [ :index, :show ]

You can specify the layout for a specific action using:

def new 
    render(:layout => "layouts/application")
end

I have never tried using multiple layout declarations in a controller. It might be that adding another

layout "standard", :only => [ :new, :edit ] 

might work...

like image 179
dtt101 Avatar answered Oct 06 '22 00:10

dtt101


If you want to use multiple layout in a controller, use the code below: ( action_name is a pre-defined variable that you could use directly in Rails)

class OrdersController < BaseController
  layout :determine_layout

private
  def determine_layout
    %w(new).include?(action_name) ? "some_layout" : "public"
  end
end

see: https://stackoverflow.com/a/5525014/445908

like image 20
Siwei Avatar answered Oct 05 '22 22:10

Siwei