On 25 March 2012 18:48, Shaban K.
<lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:> Hi I have implemented products and categories in the back-end of my
> e-commerce site. Basically I modelled it like this a product belongs_to
> a category and a category has many products. So an admin can select a
> category for a product and it saves correctly. What I would now like to
> do is show a category with all the products associated with it for
> example I have a T-shirt category so to show all the T-shirts in the
> shop. What would I need to change in my application for this to work?
You don''t need to post your whole app for such a simple question. If
you have a category in @category for example, then the products for
that category are just @category.products so you can just loop through
them displaying what you want.
Colin
>
> Attachments:
> http://www.ruby-forum.com/attachment/7187/Store_controller.txt
> http://www.ruby-forum.com/attachment/7188/db_schema.txt
> http://www.ruby-forum.com/attachment/7189/product_model.rtf
> http://www.ruby-forum.com/attachment/7190/product_model.txt
> http://www.ruby-forum.com/attachment/7191/category_model.txt
--
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.