title: Passing variables to Controller via RESTful routing in Rails
body: <p>The following question is related to passing a variable from routes to the controller. I have a Ruby on Rails (v 2.3.3) app with one model, which is delivered to the user with multiple views. The current solution involves using multiple controllers which are triggered by multiple routes. For example:</p>
  
  <pre><code>ActionController::Routing::Routes.draw do |map| # defines map
  
  map.resource :simpsons, :only =&gt; [] do |b|
    b.resources :episodes, :controller =&gt; "SimpsonsEpisodes"
  end
  map.resource :flintstones, :only =&gt; [] do |b|
    b.resources :episodes, :controller =&gt; "FlintstonesEpisodes"
  end
  </code></pre>
  
  <p>However, for the sake of DRYness I would like these routes to operate with the same controller. In order for the controller to distinct between the routes I would like to pass along a variable via the route. For example:</p>
  
  <pre><code>map.resource :simpsons, :only =&gt; [] do |b|
    b.resources :episodes, :controller =&gt; "Episodes", :type =&gt; "simpsons"
  end
  map.resource :flintstones, :only =&gt; [] do |b|
    b.resources :episodes, :controller =&gt; "Episodes", :type =&gt; "flintstones"
  end
  </code></pre>
  
  <p>So in the controller I could do this:</p>
  
  <pre><code>case(type)
  when "simpsons" then ... do something for the Simpsons ...
  when "flintstones" then ... do something for the Simpsons ...
  else      .... do something for all episodes ....
  end
  </code></pre>
  
  <p>I found a way to do this with non-RESTful routing (map.with_options etc.), but I'd prefer to use RESTful routes with map.resource(s). One ugly solution might be to parse the request URI in the controller, which I'd not prefer.</p>