Twitter Updates

Saturday 3 October 2009

Rails Menus using Partials

I have struggled to find a good tutorial on this, probably would not need it if I knew Rails better though. I would like to make a menu which is used through out my Ruby on Rails site, partials seem to be the correct thing to use.

under
app/views/
create a new folder 'shared'
and create a new file called _menu.rhtml.
'app/views/shared_menu.rhtml'

which contains the menu something like (sorry for the extra spaces only way I could stop it rendering):
< id="menu">
< class="menubar">
< class="menubar">< href="http://127.0.0.1:3000/">Home< / a>< / l i>
< class="menubar">< href="http://www.blogger.com/Posts">Posts< / a>< /l i >
< class="menubar">< href="http://www.blogger.com/Tags">Tags< / a>< / l i>
< / u l>
< / d i v>
Then add <%= render(:partial => "shared/menu") %> to all default layouts. in:
'views/layouts/*.html.erb'

No comments: