ActionController :: RoutingError(没有路由与[POST]“ / api”匹配):

时间:2018-10-31 14:00:30

标签: ruby-on-rails localhost openstreetmap

我正在使用josm创建地图,并且为此,我正在使用本地主机http://localhost:3000/api,当我使用天桥Api但使用python查询该本地主机的数据drom时,我就这样{ {1}},一旦我开始查询数据,我就从服务器上获取了它:

api = overpy.Overpass(url='http://localhost:3000/api')

似乎服务器被阻止了,任何人都可以帮忙吗?

编辑: 我的routes.rb文件如下,很抱歉添加整个文件,但是我是该字段的新手:

Started POST "/api" for 127.0.0.1 at 2018-10-31 14:57:23 +0100

ActionController::RoutingError (No route matches [POST] "/api"):

actionpack (5.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:65:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.0) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.0) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
request_store (1.4.1) lib/request_store/middleware.rb:19:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.5) lib/rack/method_override.rb:22:in `call'
rack (2.0.5) lib/rack/runtime.rb:22:in `call'
rack-uri_sanitizer (0.0.2) lib/rack/uri_sanitizer.rb:14:in `call'
activesupport (5.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
secure_headers (6.0.0) lib/secure_headers/middleware.rb:13:in `call'
railties (5.2.0) lib/rails/engine.rb:524:in `call'
puma (3.12.0) lib/puma/configuration.rb:225:in `call'
puma (3.12.0) lib/puma/server.rb:658:in `handle_request'
puma (3.12.0) lib/puma/server.rb:472:in `process_client'
puma (3.12.0) lib/puma/server.rb:332:in `block in run'
puma (3.12.0) lib/puma/thread_pool.rb:133:in `block in spawn_thread'

#API

OpenStreetMap::Application.routes.draw do

结束

get "api/capabilities" => "api#capabilities"

  scope "api/0.6" do
    get "capabilities" => "api#capabilities"
    get "permissions" => "api#permissions"

put "changeset/create" => "changeset#create"
post "changeset/:id/upload" => "changeset#upload", :id => /\d+/
get "changeset/:id/download" => "changeset#download", :as => :changeset_download, :id => /\d+/
post "changeset/:id/expand_bbox" => "changeset#expand_bbox", :id => /\d+/
get "changeset/:id" => "changeset#read", :as => :changeset_read, :id => /\d+/
post "changeset/:id/subscribe" => "changeset#subscribe", :as => :changeset_subscribe, :id => /\d+/
post "changeset/:id/unsubscribe" => "changeset#unsubscribe", :as => :changeset_unsubscribe, :id => /\d+/
put "changeset/:id" => "changeset#update", :id => /\d+/
put "changeset/:id/close" => "changeset#close", :id => /\d+/
get "changesets" => "changeset#query"
post "changeset/:id/comment" => "changeset#comment", :as => :changeset_comment, :id => /\d+/
post "changeset/comment/:id/hide" => "changeset#hide_comment", :as => :changeset_comment_hide, :id => /\d+/
post "changeset/comment/:id/unhide" => "changeset#unhide_comment", :as => :changeset_comment_unhide, :id => /\d+/

put "node/create" => "node#create"
get "node/:id/ways" => "way#ways_for_node", :id => /\d+/
get "node/:id/relations" => "relation#relations_for_node", :id => /\d+/
get "node/:id/history" => "old_node#history", :id => /\d+/
post "node/:id/:version/redact" => "old_node#redact", :version => /\d+/, :id => /\d+/
get "node/:id/:version" => "old_node#version", :id => /\d+/, :version => /\d+/
get "node/:id" => "node#read", :id => /\d+/
put "node/:id" => "node#update", :id => /\d+/
delete "node/:id" => "node#delete", :id => /\d+/
get "nodes" => "node#nodes"

put "way/create" => "way#create"
get "way/:id/history" => "old_way#history", :id => /\d+/
get "way/:id/full" => "way#full", :id => /\d+/
get "way/:id/relations" => "relation#relations_for_way", :id => /\d+/
post "way/:id/:version/redact" => "old_way#redact", :version => /\d+/, :id => /\d+/
get "way/:id/:version" => "old_way#version", :id => /\d+/, :version => /\d+/
get "way/:id" => "way#read", :id => /\d+/
put "way/:id" => "way#update", :id => /\d+/
delete "way/:id" => "way#delete", :id => /\d+/
get "ways" => "way#ways"

put "relation/create" => "relation#create"
get "relation/:id/relations" => "relation#relations_for_relation", :id => /\d+/
get "relation/:id/history" => "old_relation#history", :id => /\d+/
get "relation/:id/full" => "relation#full", :id => /\d+/
post "relation/:id/:version/redact" => "old_relation#redact", :version => /\d+/, :id => /\d+/
get "relation/:id/:version" => "old_relation#version", :id => /\d+/, :version => /\d+/
get "relation/:id" => "relation#read", :id => /\d+/
put "relation/:id" => "relation#update", :id => /\d+/
delete "relation/:id" => "relation#delete", :id => /\d+/
get "relations" => "relation#relations"

get "map" => "api#map"

get "trackpoints" => "api#trackpoints"

get "changes" => "api#changes"

get "search" => "search#search_all", :as => "api_search"
get "ways/search" => "search#search_ways"
get "relations/search" => "search#search_relations"
get "nodes/search" => "search#search_nodes"

get "user/:id" => "user#api_read", :id => /\d+/
get "user/details" => "user#api_details"
get "user/gpx_files" => "user#api_gpx_files"
get "users" => "user#api_users", :as => :api_users

get "user/preferences" => "user_preferences#read"
get "user/preferences/:preference_key" => "user_preferences#read_one"
put "user/preferences" => "user_preferences#update"
put "user/preferences/:preference_key" => "user_preferences#update_one"
delete "user/preferences/:preference_key" => "user_preferences#delete_one"

post "gpx/create" => "traces#api_create"
get "gpx/:id" => "traces#api_read", :id => /\d+/
put "gpx/:id" => "traces#api_update", :id => /\d+/
delete "gpx/:id" => "traces#api_delete", :id => /\d+/
get "gpx/:id/details" => "traces#api_read", :id => /\d+/
get "gpx/:id/data" => "traces#api_data"
# AMF (ActionScript) API
post "amf/read" => "amf#amf_read"
post "amf/write" => "amf#amf_write"
get "swf/trackpoints" => "swf#trackpoints"

# Map notes API
resources :notes, :except => [:new, :edit, :update], :constraints => { :id => /\d+/ }, :defaults => { :format => "xml" } do
  collection do
    get "search"
    get "feed", :defaults => { :format => "rss" }
  end

  member do
    post "comment"
    post "close"
    post "reopen"
  end
end

post "notes/addPOIexec" => "notes#create"
post "notes/closePOIexec" => "notes#close"
post "notes/editPOIexec" => "notes#comment"
get "notes/getGPX" => "notes#index", :format => "gpx"
get "notes/getRSSfeed" => "notes#feed", :format => "rss"

谢谢, 贾德

1 个答案:

答案 0 :(得分:0)

@max指出需要在config / routes.rb文件中定义路由:

Rails.application.routes.draw do
  post 'api', to: 'CONTROLLER_NAME#CONTROLLER_ACTION'
  ...
  ...

end

编辑:

您上面粘贴的路线文件中的每一行显示一个单独的路线。

我们需要为方法“ POST”(终点“ API”)添加一条路由,因此让我们将此行添加到路由文件的第一行和最后一行之间的任意位置:

post 'api', to: 'CONTROLLER_NAME#CONTROLLER_ACTION'

记住要为API控制器和API动作切换出控制器名称和动作。或者换种说法-您想要处理请求的控制器和操作-也许:

post 'api', to: 'api#get_records'

或保持语法一致(以下含义相同):

post "api" => "api#get_records"
相关问题