问题描述
Advanced Rails Recipes 书中21页,search那一段访问 http://localhost:3000/events/search?q=rubyconf错误提示------------------------------------------------------------------------------------------------ActiveRecord::RecordNotFound in EventsController#show Couldn't find Event with ID=searchRAILS_ROOT: C:/rubydev/ad/RESTApplication Trace | Framework Trace | Full Trace D:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1379:in `find_one'D:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1362:in `find_from_ids'D:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:537:in `find'app/controllers/events_controller.rb:16:in `show'D:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1379:in `find_one'D:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1362:in `find_from_ids'D:/Program Files/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:537:in `find'D:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in `send'D:/Program Files/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:1162:in `perform_action_without_filters'.................................................................................................RequestParameters: {"id"=>"search","q"=>"rubyconf"}Show session dump--- flash: !map:ActionController::Flash::FlashHash {}ResponseHeaders: {"cookie"=>[],"Cache-Control"=>"no-cache"}
解决方案
出现这个错误,是因为routes.rb配置的问题。这个配置了吗?map.resources :events, :collection => { :search => :get }如果配置了,将routes.rb贴出来看看。或者使用rake routes自己看下当前的routes.