Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails - How do I render an action without the application layout?

I have a rails app and I want to render an action without using my application layout (which has page header / footer stuff in it).

How could I go about doing this?

like image 636
Dean Avatar asked Oct 01 '10 16:10

Dean


People also ask

How can you tell Rails to render without a layout *?

By default, if you use the :text 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.

How do I render in Ruby on Rails?

From the controller's point of view, there are three ways to create an HTTP response: Call render to create a full response to send back to the browser. Call redirect_to to send an HTTP redirect status code to the browser. Call head to create a response consisting solely of HTTP headers to send back to the browser.

What is the difference between redirect and render in Ruby on Rails?

There is an important difference between render and redirect_to: render will tell Rails what view it should use (with the same parameters you may have already sent) but redirect_to sends a new request to the browser.

What is render partial in Rails?

Rails Guides describes partials this way: Partial templates - usually just called "partials" - are another device for breaking the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file.


2 Answers

Here's some documentation about it: http://guides.rubyonrails.org/layouts_and_rendering.html

For your question:

render :layout => false 

or

layout false 
like image 126
marcgg Avatar answered Sep 19 '22 21:09

marcgg


For Rails 5, in the controller, for the specific action:

def action
  render layout: false
end
like image 34
stevec Avatar answered Sep 20 '22 21:09

stevec