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
from a single CategoryController …
I want to show the products under their respective categories as links
get rid of the separate show page for displaying products list…

I was able to get the categories links working as expected… but
name appear simply as plain text…
<% @categories.each do |cat| %>

<%= link_to(, cat) %>
<%= cat.products.collect { |c|
%> ####-----I need links Here!!!
<% end %>
…But if I put link_to inside the cat.products.collect { |c| link_to,
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…???

On 7 April 2011 19:37, railer helper [email protected] wrote:

        <% @categories.each do |cat| %>
          <th> <%= link_to(, cat) %></th>
                <% cat.products.each do |product| %>
               <tr><td> <%= link_to h(, product%></td></tr>
                            <% end %>
         <% end %>

Since it’s a list of a category’s products, it would be more semantic
to use a

    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 %>

Thanks for the suggestion man…It works exactly as i wanted…I
know we can have a block inside another block!!!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs