I currently have a database with a table called bookstores. Within that table are columns such as bookstore name, city, state, and zip code. What I''d like to do is display the City and then every store name for that city underneath it. i.e. City - Store 1 - Store 15 Another City - Store 2 - Store 5 etc. I''ve seen act_as_tree but I don''t know if it''ll help me as I''m just using one table here. Is there a rails way to do what I want? Thanks! -- Posted via http://www.ruby-forum.com/.
I think this is probably what you''re looking for.. @bookstores_by_city = Bookstore.find_all.group_by { |store| store.city } See http://www.ruby-doc.org/core-1.9/classes/Enumerable.html -dan -- Posted via http://www.ruby-forum.com/.
Dan Kirkwood wrote:> I think this is probably what you''re looking for.. > > @bookstores_by_city = Bookstore.find_all.group_by { |store| store.city } > > See http://www.ruby-doc.org/core-1.9/classes/Enumerable.html > > -danDan, I just wanted to say thank you for your help. I''m learning more and more everyday and its great to know there''s a big community that''s willing to help you learn. -- Posted via http://www.ruby-forum.com/.