0

My aim is simply to display two optional URL parameters on an index page.

0.0.0.0:3000/comparison --> show: empty comparison index page

0.0.0.0:3000/comparison/3 --> show:

3

0.0.0.0:3000/comparison/3/4 --> show:

3
4 

I created a controller + view for "comparison"

rails generate controller comparison

and I added

match ':comparison/:index(/:a(/:b))'

to the routes.rb and added an index.html.erb displaying both parameters

<%= @a %>
<%= @b %>

my controller looks like this, simply forwarding the parameters to the view

class ComparisonController < ApplicationController
  def index 
    @a = params[:a]
    @b = params[:a]
  end
end

With this I am getting a routing error, e.g.

Routing Error

No route matches [GET] "/comparison/3/4"

How do I get the routing right?

Bernd
  • 11,133
  • 11
  • 65
  • 98
  • Is it really `match ':comparison/:index(/:a(/:b))'` and not `match 'comparison/:index(/:a(/:b))'` at the moment? – Nils Landt Nov 20 '11 at 09:53
  • I changed it. Now I get the error "ArgumentError: missing :controller" – Bernd Nov 20 '11 at 10:14
  • try this -> to catch up multiple ids thru querystring http://stackoverflow.com/questions/6413077/rails-3-custom-route-that-takes-multiple-ids-as-a-parameter – Everyman Nov 20 '11 at 11:10

1 Answers1

0

Try this route (assuming Rails version 3.x):

match 'comparison(/:a(/:b))' => "comparison#index"
Thilo
  • 17,565
  • 5
  • 68
  • 84