ruby on rails - Accessing attributes by relative :id in the view -


i have sidebar displays :users :shopping_lists. upon clicking on link list, user directed view address of: "/shopping_lists/1", 1 represents :id of shopping list. want display list items belong list in new view. i'm struggling figure out how display list items correspond relative shopping list. rails method use accomplish this? associations in place.

if associations in place, in controller can do:

@list_items = shoppinglist.find(params[:id]).list_items 

then can render @list_items template like, using collections instance.

this assuming have defined belongs_to :shopping_list association in model called listitem , has_many :list_items in shoppinglist model.


Comments

Popular posts from this blog

Using 'OR' and 'AND' in SQL Server -

python - Finding intersection between ellipse and a line -

c++ - NetBeans Remote Development with additional configuration -