ruby on rails - Rendering Partial with specific :category_id -


i created categories scaffold. user's can upload image , add category it. categories created in scaffold shown in dropdown users select.

on image show page link category ->

<%= link_to @pin.category.name, @pin.category%> 

it takes me (for example)

localhost:3000/categories/1 

on category show page want display images share same category.

how do ? 

in models define catagory

has_many :images

and image

belongs_to :category

  • image should have category_id member of course

then , when have category object in hand (let's @cat), iterate @cat.images

you can read more models , relation in here

http://guides.rubyonrails.org/association_basics.html


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -