我想知道我的路线是否会发生冲突:
我有一个相册页,它是我的用户创建相册的专用区域,用于将他们的照片存储在以下位置:
http://localhost:3000/settings/photo_gallery
从这个页面,我的用户可以创建新的专辑或点击现有的。当他们点击现有的相册以便向他们添加照片时,他们会被拍到这个页面:
http://localhost:3000/settings/photo_gallery/:id
现在我已经建立了这两条路线:
resources :photo_albums, :path => "/settings/photo_gallery"
resources :photos, :path => "/settings/photo_gallery/photos"当用户单击“添加照片”时,他们看到的页面位于:
http://localhost:3000/settings/photo_gallery/photos/new
因此,我想从页面中链接到这个页面,并在其中添加一个照片链接,我需要添加正确的路径或url链接到link_to帮助器方法。
我已经检查过rake路由,我无法真正理解如何翻译这个特定的路由,因为photo_album似乎代表了不止一个路由,我开始感到困惑了。
这是我的耙路代码:
users GET /users(.:format) {:action=>"index", :controller=>"users"}
POST /users(.:format) {:action=>"create", :controller=>"users"}
new_user GET /users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}
sessions GET /sessions(.:format) {:action=>"index", :controller=>"sessions"}
POST /sessions(.:format) {:action=>"create", :controller=>"sessions"}
new_session GET /sessions/new(.:format) {:action=>"new", :controller=>"sessions"}
edit_session GET /sessions/:id/edit(.:format) {:action=>"edit", :controller=>"sessions"}
session GET /sessions/:id(.:format) {:action=>"show", :controller=>"sessions"}
PUT /sessions/:id(.:format) {:action=>"update", :controller=>"sessions"}
DELETE /sessions/:id(.:format) {:action=>"destroy", :controller=>"sessions"}
passwords GET /passwords(.:format) {:action=>"index", :controller=>"passwords"}
POST /passwords(.:format) {:action=>"create", :controller=>"passwords"}
new_password GET /passwords/new(.:format) {:action=>"new", :controller=>"passwords"}
edit_password GET /passwords/:id/edit(.:format) {:action=>"edit", :controller=>"passwords"}
password GET /passwords/:id(.:format) {:action=>"show", :controller=>"passwords"}
PUT /passwords/:id(.:format) {:action=>"update", :controller=>"passwords"}
DELETE /passwords/:id(.:format) {:action=>"destroy", :controller=>"passwords"}
profiles GET /profiles(.:format) {:action=>"index", :controller=>"profiles"}
POST /profiles(.:format) {:action=>"create", :controller=>"profiles"}
new_profile GET /profiles/new(.:format) {:action=>"new", :controller=>"profiles"}
edit_profile GET /profiles/:id/edit(.:format) {:action=>"edit", :controller=>"profiles"}
profile GET /profiles/:id(.:format) {:action=>"show", :controller=>"profiles"}
PUT /profiles/:id(.:format) {:action=>"update", :controller=>"profiles"}
DELETE /profiles/:id(.:format) {:action=>"destroy", :controller=>"profiles"}
emails GET /emails(.:format) {:action=>"index", :controller=>"emails"}
POST /emails(.:format) {:action=>"create", :controller=>"emails"}
new_email GET /emails/new(.:format) {:action=>"new", :controller=>"emails"}
edit_email GET /emails/:id/edit(.:format) {:action=>"edit", :controller=>"emails"}
email GET /emails/:id(.:format) {:action=>"show", :controller=>"emails"}
PUT /emails/:id(.:format) {:action=>"update", :controller=>"emails"}
DELETE /emails/:id(.:format) {:action=>"destroy", :controller=>"emails"}
photos GET /photos(.:format) {:action=>"index", :controller=>"photos"}
POST /photos(.:format) {:action=>"create", :controller=>"photos"}
new_photo GET /photos/new(.:format) {:action=>"new", :controller=>"photos"}
edit_photo GET /photos/:id/edit(.:format) {:action=>"edit", :controller=>"photos"}
photo GET /photos/:id(.:format) {:action=>"show", :controller=>"photos"}
PUT /photos/:id(.:format) {:action=>"update", :controller=>"photos"}
DELETE /photos/:id(.:format) {:action=>"destroy", :controller=>"photos"}
root / {:controller=>"users", :action=>"new"}
success /success(.:format) {:action=>"success", :controller=>"users"}
login /login(.:format) {:action=>"new", :controller=>"sessions"}
logout /logout(.:format) {:action=>"destroy", :controller=>"sessions"}
reset_password /reset_password(.:format) {:action=>"new", :controller=>"passwords"}
setup_new_password /setup_new_password(.:format) {:action=>"edit", :controller=>"passwords"}
settings /settings(.:format) {:action=>"settings", :controller=>"users"}
settings_account /settings/account(.:format) {:controller=>"users", :action=>"account"}
settings_edit_profile /settings/edit_profile(.:format) {:controller=>"profiles", :action=>"edit_profile"}
/:username(.:format) {:controller=>"users", :action=>"show"}
change_password /change_password(.:format) {:action=>"change_password", :controller=>"users"}
photo_albums GET /settings/photo_gallery(.:format) {:action=>"index", :controller=>"photo_albums"}
POST /settings/photo_gallery(.:format) {:action=>"create", :controller=>"photo_albums"}
new_photo_album GET /settings/photo_gallery/new(.:format) {:action=>"new", :controller=>"photo_albums"}
edit_photo_album GET /settings/photo_gallery/:id/edit(.:format) {:action=>"edit", :controller=>"photo_albums"}
photo_album GET /settings/photo_gallery/:id(.:format) {:action=>"show", :controller=>"photo_albums"}
PUT /settings/photo_gallery/:id(.:format) {:action=>"update", :controller=>"photo_albums"}
DELETE /settings/photo_gallery/:id(.:format) {:action=>"destroy", :controller=>"photo_albums"}
GET /settings/photo_gallery/photos(.:format) {:action=>"index", :controller=>"photos"}
POST /settings/photo_gallery/photos(.:format) {:action=>"create", :controller=>"photos"}
GET /settings/photo_gallery/photos/new(.:format) {:action=>"new", :controller=>"photos"}
GET /settings/photo_gallery/photos/:id/edit(.:format) {:action=>"edit", :controller=>"photos"}
GET /settings/photo_gallery/photos/:id(.:format) {:action=>"show", :controller=>"photos"}
PUT /settings/photo_gallery/photos/:id(.:format) {:action=>"update", :controller=>"photos"}
DELETE /settings/photo_gallery/photos/:id(.:format) {:action=>"destroy", :controller=>"photos"}我剩下的路线文件:
resources :users
resources :sessions
resources :passwords
resources :profiles
resources :emails
resources :photos
root :to => "users#new"
match 'success' => "users#success"
match 'login' => "sessions#new"
match 'logout' => "sessions#destroy"
match 'reset_password' => "passwords#new"
match 'setup_new_password' => "passwords#edit"
match 'settings', :to => "users#settings"
match "/settings/account", :to => "users#account"
match "/settings/edit_profile", :to => "profiles#edit_profile"
match '/:username', :controller => 'users', :action => 'show'
match 'change_password' => "users#change_password"
resources :photo_albums, :path => "/settings/photo_gallery"
resources :photos, :path => "/settings/photo_gallery/photos"我真的很感激在这里伸出援手,我相信有一个正确的方法来解释这一点。
亲切的问候
发布于 2012-01-18 23:22:32
您已经定义了资源:照片2次在您的路由文件。你想要更早的(我希望由脚手架生成的平原‘资源:照片’)。
1)如果你不需要这条路线,你可以评论它。这样你就不会得到不明确的照片路线。
2)将资源:照片向下移动,以便路由仍然在那里,但是您的新定义可以为您提供路径(参考资料:照片:路径=>“/设置/照片_图片库/照片”)。
3)我建议移除(1)中所述的旧平原资源,或者将旧的平原资源命名为其他类似资源的东西:照片,:as => test_photos
https://stackoverflow.com/questions/8917881
复制相似问题