Rails 3 routes: How to avoid conflict with the action "show"?

Currently, the photosfollowing routes are installed:

resources :photos
match 'photos/:user' => 'photos#user', :as => :user_photo
match 'photos/:user/:key' => 'photos#show', :as => :show_photo

These two routes matchgive me URLs, for example:

http://example.com/photos/joe_schmoe
http://example.com/photos/joe_schmoe/123xyz

... similar to how Flickr formats URLs.

However, the problem is that the route is photos/:userinterpreted as a method show, or if I put these user routes before resources, then routes such as /neware interpreted as user.

How can I get around this without having to do a ton of custom routes?

+3
source share
2 answers

resources :users, .

match 'photos/:user' => 'photos#user', :as => :user_photo
resources :photos

, show:

resources :photos, :except => :show
+8

. , . - . flickr, /create/etc, . , , , , - . regexp :

match 'photos/:user' => 'photos#user', :as => :user_photo, :constraints => { :user => /.*[^n][^e][^w].*/ }

, .

+1

Source: https://habr.com/ru/post/1791779/


All Articles