Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4: You should not use the `match` method in your router without specifying an HTTP method

Okay, so I've upgraded to Rails 4 (kind of unplanned with my 10.9 server update) and have been able to get everything running on my photo gallery app except for the routes. For some reason I've always had trouble understanding routes since rails 3. Here was my previous working code under Rails 3

root :to => "gallery#index", :as => "gallery"

get 'gallery' => 'gallery#index'
resources :galleries

match 'gallery_:id' => 'gallery#show', :as => 'gallery'

I understand that match has been depreciated, but if I try to use GET, I'm getting the following error:

Invalid route name, already in use: 'gallery' You may have defined two routes with the same name using the :as option, or you may be overriding a route already defined by a resource with the same naming.

Basically, I want the root (index) to load as "/photos/gallery" as it does, and my show action to load, for example, record id 435 as: "/photos/gallery_435" which is how I previously had it working. Sorry for what is probably a simple question, I just cannot seem to grasp the rails routing.

like image 847
Cornelius Qualley Avatar asked Nov 05 '13 20:11

Cornelius Qualley


1 Answers

Try this

match 'gallery_:id' => 'gallery#show', :via => [:get], :as => 'gallery_show'

You can then refer to this path as gallery_show_path in your helpers and views.

Changing the 'as' removes the conflict.

like image 158
Peter Goldstein Avatar answered Oct 26 '22 03:10

Peter Goldstein