Reputation: 2175
Just messing around with rails layouts. Going through the guide 2.2.11.2 The :layout Option
Created a simple layout called two_column_landing and put it in the layouts directory under app/views.
Then modified my view to render the layout:
<h1>Ca#tcl</h1>
<p>Find me in app/views/ca/tcl.html.erb</p>
<%= render layout: "two_column_landing" %>
I'm getting this error:
You invoked render but did not give any of :partial, :template, :inline, :file or :text option.
I know this is probably not a great thing to be doing as a habit in production code but I'm just figuring out how to do what I want. Any ideas why this isn't working? Is it not a feature of rails 4?
Upvotes: 4
Views: 10602
Reputation: 1720
I used this and working well for rails 4
def index
@people = Person.all
render :layout => "my-layout-name"
end
Upvotes: 0
Reputation: 7339
You might keep reading. There are many ways layout can be used. If you want to call a specific layout for a given action, you should do that in a your controller, not in your view. If you need to call in a view, to give a layout for a partial, then the syntax is different, you call the partial first and then the layout.
<%= render "comments", layout: "two_column_landing" %>
If you just want you 2 column view to render in a particular controller then at the top of the controller before any method definitions call, under the class name
layout "two_column_landing"
If you want to only call this layout for a specific action in the controller you can do it in the method render
def index
@people = Person.all
render layout: "multi-column"
end
Upvotes: 2