Duncan Idaho
Duncan Idaho

Reputation: 21

route in rails does not find a query string for the main index page

I want to create a URL to the index with a query string, but I do not manage to do it. Need some help, thanks!

If I use the helper method to create URL:

link_to 'Movie Title', movie_path(:sort_by=>'title')

I get a routing error:

"No route matches {:action=>"show", :controller=>"movies", :sort_by=>:title}"

However it works when I use it with a :id, but a get a URL to movies/:id/sort_by=title and I do not want that:

link_to 'Movie Title', movie_path(1,:sort_by=>'title')

My rake routes outpus is :

    movies GET    /movies(.:format)          {:action=>"index", :controller=>"movies"}
           POST   /movies(.:format)          {:action=>"create", :controller=>"movies"}
 new_movie GET    /movies/new(.:format)      {:action=>"new", :controller=>"movies"}
edit_movie GET    /movies/:id/edit(.:format) {:action=>"edit", :controller=>"movies"}
     movie GET    /movies/:id(.:format)      {:action=>"show", :controller=>"movies"}
           PUT    /movies/:id(.:format)      {:action=>"update", :controller=>"movies"}
           DELETE /movies/:id(.:format)      {:action=>"destroy", :controller=>"movies"}

Upvotes: 0

Views: 870

Answers (1)

klump
klump

Reputation: 3269

movie_path is for one movie - if you want a list you should user movies_path

Have a look here: http://guides.rubyonrails.org/routing.html#resource-routing-the-rails-default

edit: added link

Upvotes: 6

Related Questions