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

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -