Search code examples
ruby-on-railsrenderingruby-on-rails-4scaffolding

Render only Items with a specific id


I render my Item's via <%= render @items%>

I added a migration AddCatIdToItems cat_id:string

Cat_id's: testA, testB, testC.

how can I render only items with the specific id testA?

e.g.: <&= @items.where(:cat_id => '1')&>

I use a seed file to populate the Item's. e.g.:

Tag.create([
            { name: 'example' },
            { name: 'example2' },
            { name: 'example3' }
           ])

How can i pass the cat_id into that?

is { name: 'example', cat_id:1 } working?


Solution

  • I am not sure what you are asking for. But I guess this is what you want

    @items = Item.where("cat_id LIKE '%testA%'")
    

    If you want to select all the items that have a specific cat_id, then

     @items = Item.where(:cat_id => 'testA')