Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4: set layout equal to false in controller

In a Rails 4 app I am trying to set the layout to false or nil. I tried this from inside my controller:

render :layout => false

But that gives this error:

undefined method `render'.

How can I stop this controller from using the default layout file?

like image 783
Mark Locklear Avatar asked Apr 01 '14 17:04

Mark Locklear


2 Answers

To disable layout for a controller:

class FooController < ApplicationController
  layout false
  ...
end
like image 142
vee Avatar answered Nov 19 '22 04:11

vee


Scenario 1: To disable layout for all the actions of a controller use it as:

class FoosController < ApplicationController
   layout false  ## Note it is not within any action

   def create
   ...
   end

...
end

Scenario 2: To disable layout for a specific action of a controller use it as:

class FoosController < ApplicationController
  ...
  def show
   ...
   render layout: false
  end
  ...
end
like image 6
Kirti Thorat Avatar answered Nov 19 '22 02:11

Kirti Thorat