i have 2 models items and categories..in items listing i have category name,title...etc.. In item edit page i want to display the title of all item having the same category name.means when clicking on edit field of one item it should show edit details and the title of the items which have the same catoegory name.how can i do this ...so i think have to use some find method or something..then where should i write the code? in item controller ?then how can i call it from my listing items ?somebody help me pls.........
If you are using rails 2.1 then you can use a named scope on the Item model like such
== in Item belongs_to :category named_scope :same_category, :include => :category, :conditions => { 'category.name' => category.name } then you can do
== IteamsController (i suppose) def edit @iteams = Item.same_category @item = ... end
and it will do the find for you.
have a look at: #108 named_scope - RailsCasts