Reputation: 17486
I am in ruby 1.9.2, rails3.
So My website has some structures,
and I want to put menu in a middle of my webpage.
I am doing something like (within application.html.erb file)
blahblahblah
<div id="menu">
<%= yield :menu %>
<div>
blahblhablah
I have a file menu.html.erb which has menu structure for the site. What can I do if I want to use a file within ./layout folder to be used to be part of that yield :menu? I was wondering, if I have to use content_for for every controller, and within every functions... Btw, menu.html.erb will be different for each controller, so thats why I am yielding it.
In conclusion, I just want to include one common shared menu.html.erb pretty much everywhere.
Upvotes: 0
Views: 820
Reputation: 4094
You might consider watching the railscast on layouts, it's concise and helpful. Numbers 7 and 8.
http://railscasts.com/episodes?search=layout
Upvotes: 1
Reputation: 2736
You could do something like this in your views:
<% content_for(:menu) do %>
<%= render :partial => "/layouts/user_menu.html.erb" %>
<% end %>
You could try to combine this with controller.controller_name
(not sure this works for Rails3) and load a different menu for each controller automatically.
Upvotes: 5