Suppose I have the following:
In layouts/application.rhtml
<HTML>
<HEAD>
<TITLE> Title </TITLE>
</HEAD>
<BODY>
<div>
<%= render(:partial => "shared/navigation_bar") -%>
</div>
<div>
<%= @content_for_layout -%>
</div>
</BODY>
</HTML>
and in the partial (shared/_navigation_bar) I have:
<table>
<td>
<%= link_to "My Cart", { :controller => "cart",
:action =>
"my_cart" } -%>
</td>
</tr>
</table>
My question is...How can I toggle whether the "My Cart" link is shown
depending on if there is anything in the cart?
If I put:
def some_action
@cart = find_cart
...some other code...
end
I can reference this is the partial(which is in the layout) like this:
<% if @cart %>
<table>
<td>
<%= link_to "My Cart", { :controller => "cart",
:action =>
"my_cart" } -%>
</td>
</tr>
</table>
<% end %>
However, if I don''t include the code in EVERY action, there will be an
error for that page. The DRY principle tells me I should not just be
adding the @cart = find_cart code to every dang action on the controller
just so I can have a little logic in the nav bar. So, what is the best
way to do this? The find_cart method is a private method in the
application controller.
Thanks,
Shagy
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---