0

Rails4.0を使用しています

routes.rb にはコードがあります

get "test/index"

それは正常に動作します。しかし、次のようなカスタムルートを追加すると:

post "test/some_controller_action"

そして、curl経由でファイルを送信します

curl -X POST -H "Content-type: application/json" -d @result.json http://localhost:3000/test/some_controller_action

エラーが発生します

Started POST "/test/some_controller_action" for 127.0.0.1 at 2013-07-15 14:28:11 +0700
ActionController::RoutingError (No route matches [POST] "/test/some_controller_action"):
  actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
  activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
  railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
  railties (4.0.0) lib/rails/engine.rb:511:in `call'
  railties (4.0.0) lib/rails/application.rb:97:in `call'
  rack (1.5.2) lib/rack/lock.rb:17:in `call'
  rack (1.5.2) lib/rack/content_length.rb:14:in `call'
  rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'

レーキルート:

Prefix Verb URI Pattern                   Controller#Action
test_index GET  /test/index(.:format)      test#index
test_some_controller_action POST /test/some_controller_action(.:format) test#some_controller_action

そのルートの何が問題になっていますか?

4

2 に答える 2

0

保守性が向上するため、他の形式よりもこの形式を好みます。:on => :collection好きな方法で、その部分が重要であることに注意してください。

resources :test do
  post :some_controller_action, :on => :collection
end

HTH

于 2013-07-15T10:41:06.890 に答える