How to specify nested parameters in the routes
In routes.rb I have described how the search will look like this
match "results//:transaction/:city(.:format)" => "search#index", :as => :seo_search_index
which generates me this kind of routes
seo_search_index /results/:transaction/:city(.:format) {:action=>"index", :controller=>"search"}
And the params object is filled with
params[:tra开发者_开发问答nsaction]
params[:city]
params[:zip5]
But I want the param object to be filled like this
params[:search][:transaction]
params[:search][:city]
params[:search][:zip5]
Is there a way to specify this like this
Just an example:
match "results//:search[transaction]/:search[city](.:format)" => "search#index", :as => :seo_search_index
I'm not sure there's a way to tell the Rails routing system that you want your parameters nested. You could work around this issue with a before filter in your controller:
class MyController < ApplicationController
before_filter do
params[:search] = params.slice(:transaction, :city, :zip5)
end
end
Update
To answer your real question, you could do either:
seo_search_index_url(@search)
or
seo_search_index_url(@search.slice(:transaction, :city, :zip5))
depending on whether the @search
hash contains only the keys you want or some additional ones.
With the help routing filter you can make what ever you want with the urls https://github.com/svenfuchs/routing-filter
精彩评论