Rails 3 dynamic route

Hi all

My problem is simple :

I have a link which points on :

In my route, I’d like this link calls “products/index” BUT I want this
URL in the browser : “products/category/#{name}”

Using Rails 3 I instinctively tried :

match “products/category/:id/:name”, :to => “products#index”, :as =>

But the server doesn’t even run because of #{name} in :as
I don’t know how to precise a dynamic value in :as or maybe I am totally



match “products/category/:id/:name” => “products#index”

the :as argument is for named_routes. if you want a named_route you can
instead use

match “products/category/:id/:name” => “products#index”, :as =>

then in your views, you can use the named route

product_category_path(‘1’, ‘foo’)

which will produce


On Tue, Feb 8, 2011 at 2:54 PM, Lune L. [email protected] wrote:

Using Rails 3 I instinctively tried :