I have a model, Download, with a HABTM relationship to another model, Product. In the index view for Download, I want to list all of the associated products by name. Here is my view code for the table row: <script src="http://gist.github.com/73492.js"></script> I''ve tried using "download.products.join('', '')", but all I get is the objects has mark (#) in my HTML. Is there a quick and easy way of creating a joined list of all the product names that I just don''t know about? Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sorry, here''s my view code: <tr class="<%= cycle(''off'', ''on'') %>"> <td><%= link_to(download.title, edit_download_path(download)) %></td> <td><%= link_to(download.file_name, download_path(download)) %></td> <td><%= download.part_number %></td> <td> <% download.products.each do |product| -%> <%= product.name %>, <% end -%> </td> <td class="delete"><%= link_to(''×'', download_path (download), :confirm => "Are you sure you want to delete # {download.title}?", :method => ''delete'') %></td> </tr> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Mar 3, 8:07 pm, partydrone <partydr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a model, Download, with a HABTM relationship to another model, > Product. In the index view for Download, I want to list all of the > associated products by name. Here is my view code for the table row: > > <script src="http://gist.github.com/73492.js"></script> > > I''ve tried using "download.products.join('', '')", but all I get is the > objects has mark (#) in my HTML. Is there a quick and easy way of > creating a joined list of all the product names that I just don''t know > about?when you call join on products it calls to_s on each Product, because it doesn''t know any better (and the particular details of the default to_s on objects means that what you get is invalid html that is often displayed as just # by browers). It''s up to you to turn that array of products into an array of suitable strings (checkout the select/map methods on Array) and then call join on that Fred> > Thanks.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, Mar 3, 2009 at 2:07 PM, partydrone <partydrone-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve tried using "download.products.join('', '')", but all I get is the > objects has mark (#) in my HTML. Is there a quick and easy way of > creating a joined list of all the product names that I just don''t know > about?<%= @download.products.collect{ |p| p.name }.join( '', '' ) %> -- Greg Donald http://destiney.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 -~----------~----~----~----~------~----~------~--~---