On Fri, Aug 26, 2011 at 3:07 AM, doabit <[email protected]> wrote: > 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. > > 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.
> -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

