railer helper
2011-Apr-07 18:37 UTC
How to display the list of children as links under their respective parent
Hey.....Does nybody know how to display a list(array) as links
Eg: I''ve a @products and @categories enumerable objects supplied to the
view
from a single CategoryController ...
I want to show the products under their respective categories as links and
get rid of the separate show page for displaying products list...
I was able to get the categories links working as expected... but products
name appear simply as plain text.....
<% @categories.each do |cat| %>
<th> <%= link_to( cat.name, cat)
%></th>
<tr><td> <%= cat.products.collect { |c|
c.name }
%> </td></tr> ####-----I need links Here!!!!!!!!!!!!!!
<% end %>
...But if I put link_to inside the cat.products.collect { |c| link_to c.name,
c }, I get the html escaped text for links inside the[..]
Category and Product models have has_many_through relationship...
How to go about this......??????????
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling
2011-Apr-07 20:12 UTC
Re: How to display the list of children as links under their respective parent
On 7 April 2011 19:37, railer helper <railerhelper-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> <% @categories.each do |cat| %> > <th> <%= link_to( cat.name, cat) %></th><% cat.products.each do |product| %>> <tr><td> <%= link_to h(product.name), product %></td></tr><% end %>> <% end %>Since it''s a list of a category''s products, it would be more semantic to use a <ul> element rather than lots of rows in the table though. Oh, and BTW - you''ll want to html escape the category name too... <%= link_to h(cat.name), cat %> -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
railer helper
2011-Apr-08 06:59 UTC
Re: How to display the list of children as links under their respective parent
Thanks for the suggestion man....It works exactly as i wanted.....I din''t know we can have a block inside another block!!! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.