Rails 3 dynamic route

Hi all

My problem is simple :

I have a link which points on :
“products/category/#{category.id}/#{category.name}”

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 =>
“products/category/#{name}”

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
wrong.

Thanks

use

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 =>
:product_category

then in your views, you can use the named route

product_category_path(‘1’, ‘foo’)

which will produce

products/category/1/foo

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

Using Rails 3 I instinctively tried :

http://groups.google.com/group/rubyonrails-talk?hl=en.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs