Mano Svajone
2014-Jul-20 01:00 UTC
view for has_many and belongs_to but with only one associated record
Restaurant Load (1.5ms) SELECT * FROM "restaurants" INNER JOIN "restaurant_branches" ON "restaurant_branches"."restaurant_id" "restaurants"."restaurant_id" +----------+---------+---------+---------+----------+---------+----------+---------+---------+---------+---------+---------+---------+---------+---------+-------+ | resta... | res_... | res_... | crea... | updat... | user_id | resta... | addr... | addr... | addr... | addr... | addr... | addr... | numb... | numb... | email | +----------+---------+---------+---------+----------+---------+----------+---------+---------+---------+---------+---------+---------+---------+---------+-------+ | 27 | DOGG... | WE S... | 2014... | 2014-... | 4 | 28 | 405 ... | | CHICAGO | IL | 60666 | USA | | | | | 27 | DOGG... | WE S... | 2014... | 2014-... | 4 | 29 | 111 ... | | CHICAGO | IL | 60661 | USA | | | | +----------+---------+---------+---------+----------+---------+----------+---------+---------+---------+---------+---------+---------+---------+---------+-------+ As you can see, I have two records for record 27. This is from a joined table between restaurants and restaurant_branches. How would I approach this in a view so that when I select a record on my index.html.erb file when it gets routed to the show.html.erb file it'll only take one row of that record and only show me one branch instead of 2? Thank you for any help. -- 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/91a09235a01d850bda588d149bb1640e%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.