On 26 May 2011 23:12, Caroline M. <li...@ruby-forum.com> wrote: > ... > Colin, > > i tried to implement what you said i have all the fields now in one > table. im still having a few hiccups with the views and some actions. > > in products index i want the products created by user_id 1 only to > display. user_id 1 is my admin user.
In the controller fetch the records where that is the id. @products = Product.where( :user_id => 1) or if you actually have the admin user available as an object then @products = admin_user.products which is much nicer. > > on the user_products controller in the index view i want the products > of the logged in user only to display, In this case @products = current_user.products > maybe if user_id 1 is logged in > they could see all products created by other users. If User has a method admin? that tells you whether he is the admin user (much better than relying on id) @products = current_user.admin? ? Product.all : current_user.products > > also when i create a product in the user_product new view after i press > create it reverts the product back to the products index instead of > keeping it in an user_products index view, which is what i want as i > have different fields on display for the two different types. so if i > click show etc it displays products show view page but what i want for > that product is the user_product show view page. Where it goes after the create action is up to the code you have written. After the save call you probably have a redirect_to statement which tells the browser which page to fetch next. In each controller specify where you want it to go. I think in an earlier post I suggested working through railstutorial.org. This would really be a good idea, at some point you will look back on these questions and be embarrassed that you had to ask them. :) Colin -- 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@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.