Colin Law wrote in post #1001188: > On 26 May 2011 11:38, Caroline M. <[email protected]> wrote: >>> maybe just have some way of knowing what sort each product is. Then >>> from the point of view of your cart life would be easy. >>> >>> Colin >> >> thanks colin, i was trying to think about this already but not sure >> really what way to do it. im new to all this. i need the two separate >> controllers for the tables because i want users to be able to use the >> new/user_products path creating their own products, while on the >> products controller the new path is not visible to users. > > You don't have to have separate models in order to have two > controllers, both controllers can access the same model. Possibly the > simplest way, to avoid the complications of STI, would just be to put > all the columns you need for both types of product in one table and > maybe use a special entry in the category table to say that is is a > user model. Or alternatively a new column to indicate the type (don't > call it 'type' though or rails will think you are using STI). Then > just leave the unused columns empty. > >> i prob also >> need to add user_id to the user_products table. im not sure how to >> combine the tables. im tryna fins stuff on net on STI but im not really >> understanding it too well. > > Again this will be much easier if you stick to one table. I presume > you know about ActiveRecord relationships, if not have a look at the > Rails Guide on relationships. You can say Product belongs to User and > User has many Products. This will require a user_id column in the > products table. Then you could use the fact that the user_id is nil > to indicate that it is an ordinary product rather than a user product, > rather than use a special category. I am sure you know that then if > you have a user in @user then @user.products will give you all his > products. > > I am assuming here that user products are different products to normal > ones (rather than just being 'ordinary' products that relate in some > way to the user). If they are actually just the same products then > you would want a different setup altogether. > > Colin
Colin thanks so much for your help. the user products are products were the user can upload a photo using paperclip creating their own personalized products. so if im understanding correctly your saying to get rid of user_products table and add the fields for this table into the products table. and that i still have a products controller and user_products controller for the views to create the different products...however wont the user_products controller create them as user_products, not products? and not be read into the cart then. > Then you could use the fact that the user_id is nil > to indicate that it is an ordinary product rather than a user product, > rather than use a special category. where would i use this? -- 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 post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

