2

私は以下を取得しています:

Started DELETE "/comments/13115742" for 127.0.0.1 at 2012-11-26 14:37:32 -0800

ActionController::RoutingError (No route matches [DELETE] "/comments/13115742"):

しかし、「rake routes」はこのルートを明確に示しています:

$ rake routes
comments POST   /comments(.:format)                comments#create {:id=>/0-9+/, :format=>/json|html/}
 comment GET    /comments/:id(.:format)            comments#show {:id=>/0-9+/, :format=>/json|html/}
         PUT    /comments/:id(.:format)            comments#update {:id=>/0-9+/, :format=>/json|html/}
         DELETE /comments/:id(.:format)            comments#destroy {:id=>/0-9+/, :format=>/json|html/}

そして、routes.rb には明確にルートが定義されています。

resources :comments, :constraints => {:id => /0-9+/, :format => /json|html/}, :except => [:new, :index, :edit]

コメント コントローラーがあり、コンソールからのルーティングも機能しないことに注意してください。

Loading development environment (Rails 3.2.8)
irb(main):001:0> r = Rails.application.routes
=> #<ActionDispatch::Routing::RouteSet:0x007f9ae17b66e0>
irb(main):002:0> r.recognize_path "/comments/3"
ActionController::RoutingError: No route matches "/comments/3"
    from /Users/nick/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:633:in `recognize_path'
    from (irb):2
    from /Users/nick/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
    from /Users/nick/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
    from /Users/nick/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
irb(main):003:0> CommentsController.new()
=> #<CommentsController:0x007f9ae3f9d9b0 @_routes=nil, @_action_has_layout=true, @_headers={"Content-Type"=>"text/html"}, @_status=200, @_request=nil, @_response=nil>

助言がありますか?

4

1 に答える 1

4

現在、制約は意図した数値文字列と一致しませ:idん。

の代わりに、または/0-9+/を試してください/[0-9]+//\d+/

あなたが持っているものは、/conversations/0-9または/conversations/0-9999999

于 2012-11-26T23:05:27.243 に答える