views:

21

answers:

1

I was trying to switch the layout using Ruby on Rails but I am getting the error: undefined method `layout' for #. I am using Rails 2.3.5 Am I missing an include?

Here is the code:

class HelloController < ApplicationController

  def index

    layout 'standard'
    @message = "Goodbye!"
    @count = 3
    @bonus = "This is the bonus message!"
  end

end
+4  A: 

If you are using layout as such, it goes in the Class definition, not an action.

class HelloController < ApplicationController

  layout 'standard'

  def index
    ...

This is saying that you want to use this layout for rendering all actions in this controller.

If you want a specific layout for that one action, you would use render :layout as so:

  def index
    @message =
    ...
    render :layout => 'standard'
  end

EDIT: the docs (towards the bottom) seem to suggest that you need to specify the action, as well as the layout when using a specific layout for one action. I don't remember that being the case, but if it is, the above would be render :action => 'index', :layout => 'standard'.

theIV