How to write link_to method to Rails route globbing

I have a product page,I want to change the url "example.com/products/ list?category_id=1&price_id=5&type_id=2&sort_by=name&......" to

"example.com/products/list/category_id/1/price_id/5/type_id/2/sort_by/ name.....". my routes like

  match '/products/list(/*specs)', :controller => 'products', :action => 'list',:as => :list_products My controller

  @products=Product.scoped   @products = @Product.where(Hash[*params[:specs].split("/")]) if params[:specs] In my views:

  Categories:   <% Category.all.each do |category| %>   <p><%= link_to category.name,list_products_path(:specs => ['category', category]) %></p>   <% end %>   Price:   <% Prices.all.each do |price| %>   <p><%= link_to price.name,list_products_path(:specs => ['local', local]) %></p>   <% end %> I wnat to get url like /products/list/category/1/local/2... ,but it can only get url like /products/category/1 or /news/local/2. How to write the link_to method to make it works? Thank you.

I have a product page,I want to change the url "[example.com/products/

list?category_id=1&price_id=5&type_id=2&sort_by=name&…](http://example.com/products/ list?category_id=1&price_id=5&type_id=2&sort_by=name&…)." to

"example.com/products/list/category_id/1/price_id/5/type_id/2/sort_by/

name…".

my routes like

match ‘/products/list(/*specs)’, :controller => ‘products’, :action

=> ‘list’,:as => :list_products

My controller

@products=Product.scoped

@products = @Product.where(Hash[*params[:specs].split(“/”)]) if

params[:specs]

In my views:

Categories:

<% Category.all.each do |category| %>

<%= link_to [category.name](http://category.name),list_products_path(:specs =>

[‘category’, category]) %>

<% end %>

Price:

<% Prices.all.each do |price| %>

<%= link_to [price.name](http://price.name),list_products_path(:specs => ['local',

local]) %>

<% end %>

I wnat to get url like /products/list/category/1/local/2… ,but it

can only get url like /products/category/1 or /news/local/2. How to

write the link_to method to make it works? Thank you.

Setup your routes using nested resources. http://guides.rubyonrails.org/routing.html#nested-resources

After setting that up, use rake routes to find the url you need.