title: Rails - Indexing records based on their category
body: <p>My project is setup where each movie has many genres and each genre has many movies. So for instance a movie can have one or more genres of such categories: Action, Comedy, Drama. What I'd like to do is create views for each genre that list the movies that belong to them, similar to how the default index action is setup:</p>
  
  <pre><code>class Movie &lt; ActiveRecord::Base
      attr_accessor :name
      has_many :genreships
      has_many :genres, through: :genreships
  
      extend FriendlyId
      friendly_id :name, use: :slugged
  end
  
  class Genreship &lt; ActiveRecord::Base
      belongs_to :movie
      belongs_to :genre
  end
  
  class Genre &lt; ActiveRecord::Base
      attr_accessor :name
      has_many :genreships
      has_many :movies, through: :genreships
  
      extend FriendlyId
      friendly_id :name, use: :slugged
  end
  </code></pre>
  
  <p><strong>Movies Controller</strong></p>
  
  <pre><code>def index
    @movies = Movie.all
  end
  </code></pre>
  
  <p><strong>Movies Index View</strong></p>
  
  <pre><code>&lt;% @movies.each do |movie| %&gt;
    ...
  &lt;% end %&gt;
  </code></pre>
  
  <p>With each genre-based url looking something like this: <code>localhost:3000/comedy</code></p>
  
  <p>I realize that creating an index action for each and every genre wouldn't scale well so I'm wondering what would be the best solution to dynamically create these pages. I've done some research regarding to the topic but most of them have been geared towards creating <em>nested routes</em> where as I'm leaning more towards the Action View.</p>