title: How do i access names of one model from relationship of three models?
body: <p>I need to print out in the index view, all <strong>items</strong> from a certain <strong>city</strong> under  <strong>category</strong> 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</p>
  
  <pre><code>    class CategoryController &lt; ApplicationController
      def index
      @city= City.find(session[:city_id])
      @items=@city.items
      end
      end
  </code></pre>
  
  <p>index view</p>
  
  <pre><code>     &lt;%=@item.each do |item|%&gt;
       &lt;%=item.item_name%&gt;
       &lt;%end%&gt;
  </code></pre>
  
  <p>Models</p>
  
  <pre><code>       class City &lt; ActiveRecord::Base
         has_many :items 
         end
  
         class Item &lt; ActiveRecord::Base
     belongs_to :city
     belongs_to :category
         end
  
         class Category &lt; ActiveRecord::Base
         has_many :items
         end 
  </code></pre>