Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove application layout from a particualar Ruby on Rails page?

How can I remove the layout application.html.erb from rendering on a particular page. It is now visible on all pages in my application.

like image 980
Themasterhimself Avatar asked Jun 06 '11 07:06

Themasterhimself


People also ask

How can you tell Rails to render without a layout?

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.

How do you render a partial?

Rendering a Partial View You can render the partial view in the parent view using the HTML helper methods: @html. Partial() , @html. RenderPartial() , and @html.

What keyword is used in a layout to identify a section where content from the view should be inserted?

Within the context of a layout, <%= yield %> identifies a section where content from the view template should be inserted. The simplest way to use this is to have a single yield, into which the entire contents of the view currently being rendered is inserted.


2 Answers

You can override default rendering at the controller level.

class Admin::HomeController < Admin::BaseController
  layout "admin"

You can also override rendering of layouts at a controller action level:

def show
  render :layout => "layout_for_show_only"
end

And, if you are really desperate, you can override layouts in the view:

<%= render "print_view", :layout => "print" %>

See the excellent rails guide on the subject: layouts and rendering in Rails

ian.

like image 70
ipd Avatar answered Oct 13 '22 00:10

ipd


You can simply add to the controller:

layout false, only: [:show, :edit]

which means, that application layout won't be rendered for the show and edit pages

like image 29
Sergey Mell Avatar answered Oct 13 '22 02:10

Sergey Mell