I need to print out in the index view, all items from a certain city under category with id 2(any number).So far i have instance of all items in the city(as shown below),now i want to filter them by category.How do i do that?This is my code below
class CategoryController < ApplicationController
def index
@city= City.find(session[:city_id])
@items=@city.items
end
end
index view
<%=@item.each do |item|%>
<%=item.item_name%>
<%end%>
Models
class City < ActiveRecord::Base
has_many :items
end
class Item < ActiveRecord::Base
belongs_to :city
belongs_to :category
end
class Category < ActiveRecord::Base
has_many :items
end
Controller:
You should be able to do something like:
Or something like:
View: