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
If you are using
layoutas such, it goes in the Class definition, not an action.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 :layoutas so: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'.