开发者

Permutation on Rails Routes

开发者 https://www.devze.com 2023-01-01 19:10 出处:网络
I currently have an application that for a set of parameters (location, category, budget, ...) a user can enter a \"pretty\" URL like:

I currently have an application that for a set of parameters (location, category, budget, ...) a user can enter a "pretty" URL like:

/location/canada/ontario

/category/primary

/budget/small

Resulting in the respective parameters:

params[:country] == 'canada' and params[:region] == 'ontario'
params[:category] == 'primary'
params[:budget] == 'small' 

I want to allow users to perform searches on multiple parameters a开发者_Python百科t once (with each parameter optional). For example:

/location/canada/ontario/category/primary/budget/small

/location/canada/ontario/category/primary /budget/small/category/primary /category/primary/budget/small

I understand that this can be achieved using URL parameters, but for SEO reasons I prefer to add the "pretty" parameters. Is this at all possible without listing all possible combination of routes (I have a large number of search-able fields)? I understand that route "globbing" maybe play a roll, but I am not sure how.

Thanks.


Ended up giving up in Rails 2. Upgraded application to Rails 3 and used optional parameters:

match 'filter(/budget/:budget)(/category/:category)(/location/:country(/:region))' => 'filter#index', :as => :filter
0

精彩评论

暂无评论...
验证码 换一张
取 消