在Rails中获得意外的路由错误3.帮助?
来自routes.rb的相关行:
# Profile photos
match 'people/:user_id/profile-photos' => 'profile_photos#index', :as => :profile_photos
match 'people/:user_id/profile-photo/:id' => 'profile_photos#show', :as => :profile_photo
match 'settings/profile/profile-photos/new' => 'profile_photos#new', :as => :new_profile_photo
match 'settings/profile/profile-photos/create' => 'profile_photos#create', :as => :create_profile_photo
match 'settings/profile/profile-photos/:id/edit' => 'profile_photos#edit', :as => :edit_profile_photo
match 'settings/profile/profile-photos/:id/update' => 'profile_photos#update', :as => :update_profile_photo
match 'settings/profile/profile-photos/delete' => 'profile_photos#destroy', :as => :destroy_profile_photo
我在profile_photos_controller.rb中的操作:
def new
@profile_photo = ProfilePhoto.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @profile_photo }
end
end
'rake routes'包括以下内容(在任何地方都没有提及ProfilePhotosController):
profile_photos /people/:user_id/profile-photos(.:format) profile_photos#index
profile_photo /people/:user_id/profile-photo/:id(.:format) profile_photos#show
new_profile_photo /settings/profile/profile-photos/new(.:format) profile_photos#new
create_profile_photo /settings/profile/profile-photos/create(.:format) profile_photos#create
edit_profile_photo /settings/profile/profile-photos/:id/edit(.:format) profile_photos#edit
update_profile_photo /settings/profile/profile-photos/:id/update(.:format) profile_photos#update
destroy_profile_photo /settings/profile/profile-photos/delete(.:format) profile_photos#destroy
但是当我去http://localhost:3000/settings/profile/profile-photos/new
时,我得到了:
Routing Error
No route matches {:controller=>"profile_photos", :format=>nil}
另一方面, http://localhost:3000/settings/profile/profile-photos
可以正常工作。
回溯:
Started GET "/settings/profile/profile-photos/new" for 127.0.0.1 at 2012-08-16 21:04:03 +1000
Processing by ProfilePhotosController#new as HTML
Rendered profile_photos/_form.html.erb (2.4ms)
Rendered profile_photos/new.html.erb within layouts/application (3.9ms)
Completed 500 Internal Server Error in 9ms
ActionController::RoutingError (No route matches {:controller=>"profile_photos", :format=>nil}):
app/views/profile_photos/_form.html.erb:1:in `_app_views_profile_photos__form_html_erb___2215516803448970113_2172918840'
app/views/profile_photos/new.html.erb:3:in `_app_views_profile_photos_new_html_erb___297473120476707709_2157340820'
app/controllers/profile_photos_controller.rb:23:in `new'
Rendered /Users/rebecca/.rvm/gems/ruby-1.9.3-p0@eventful2/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.1ms)