views:

43

answers:

2

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.

+3  A: 

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.

Maran
that's how i would do it too.
Sam
How can I combine controller.controller_name... Make a controller folder and make another controller file?
A: 

You might consider watching the railscast on layouts, it's concise and helpful. Numbers 7 and 8.

http://railscasts.com/episodes?search=layout

dah