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
Rendering means interpolating the template with context data and returning the resulting string. The Django template language is Django's own template system.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With