Thursday, January 7, 2010

Ruby on Rails shareble content or menus processing

Store the common menus or links in some where in app/views folder with filename prefixing with _. Ex store the links in app/views/shared/_global_links.rhtml file and call it in app/views/layouts/application.rhtml file.

Ex: app/views/shared/_global_links.rhtml
<% if logged_in? %>
<%= current_user.login %> |
<%= link_to "Dashboard", root_url %> |
<%= link_to "My Account", profile_url(current_user) %> |
<% if admin? -%><%= link_to "Administration", admin_root_url %> | <% end -%>
<%= link_to "Log out", logout_url, :method => :delete %>
<% else %>
<%= link_to "Sign up", signup_url %> |
<%= link_to "Log in", login_url %>
<% end %>

#app/views/layouts/application.rhtml
-------------------------------------------------------
-------------------------------------------------------


<%= render :partial => 'shared/global_links' %>

-------------------------------------------------------
-------------------------------------------------------

0 comments: