Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render a template and layout?

In a controller method, how can you render a template and layout?

Like so:

def new
  render :template => 'devise/invitations/new', :layout => 'application_unauthorized2_t2' 
end
like image 515
AnApprentice Avatar asked May 12 '11 21:05

AnApprentice


People also ask

What does rendering a template mean?

Rendering means interpolating the template with context data and returning the resulting string. The Django template language is Django's own template system.

What is a layout template in Rails?

In Rails, layouts are pieces that fit together (for example header, footer, menus, etc) to make a complete view. An application may have as many layouts as you want. Rails use convention over configuration to automatically pair up layouts with respective controllers having same name.

How can you tell Rails to render without a layout?

2.2. By default, if you use the :plain option, the text is rendered without using the current layout. If you want Rails to put the text into the current layout, you need to add the layout: true option and use the . text. erb extension for the layout file.

What is a layout in Ruby on Rails?

A layout defines the surroundings of an HTML page. It's the place to define a common look and feel of your final output. Layout files reside in app/views/layouts. The process involves defining a layout template and then letting the controller know that it exists and to use it.


1 Answers

Instead of just being an options hash, like most rails methods, the render method is a series of arguments, the last of which is an options hash. The first argument to render is the template, as a string. You don't need to include it in the options hash.

Just do this:

def new
  render 'devise/invitations/new', :layout => 'application_unauthorized2_t2' 
end
like image 75
Mario Avatar answered Oct 10 '22 05:10

Mario