【发布时间】:2017-10-10 09:38:01
【问题描述】:
使用 CURL 或 POSTMAN 客户端点击时找不到我的以下 API 路由
Started POST "/api/users/register_handheld" for 181.74.100.34 at 2017-05-11 11:27:42 +0000
DEBUG: Chewy strategies stack: [2] <- atomic @ /home/deploy/boold/shared/bundle/ruby/2.2.0/gems/chewy-0.8.4/lib/chewy/railtie.rb:17
ActionController::RoutingError (No route matches [POST] "/api/users/register_handheld"):
但是当我运行 rake routes 时,这个 URL 是存在的。
api_users_register_handheld POST /api/users/register_handheld(.:format)
crowd/api/v1/handheld_users#create {:format=>"json"}
如果我在 Rails 控制台中点击,此 URL 确实有效:
app.post "/api/users/register_handheld"
Started POST "/api/users/register_handheld" for 127.0.0.1 at 2017-05-11 11:21:03 +0000
DEBUG: Chewy strategies stack: [3] <- atomic @ /home/deploy/boold/shared/bundle/ruby/2.2.0/gems/chewy-0.8.4/lib/chewy/railtie.rb:17
Processing by Crowd::Api::V1::HandheldUsersController#create as JSON
路由文件是
namespace :api, defaults: {format: 'json'} do
scope module: :v1 do
resources :dashboard, controller: "account/dashboard"
post '/account/settings/create_notification' => 'account/settings#create_notification'
post '/users/register' => 'users#create'
post 'users/register_handheld' => 'handheld_users#create'
put 'users/update_profile' => 'handheld_users#update_profile'
post 'users/login' => 'handheld_users#login'
注意:这个 repo 是 Rails Engine
【问题讨论】:
-
添加你的路由..正如我所见,你有版本控制命名空间..可能你错过了..
v1 -
不,@Md.FarhanMemon 那么来自控制台的请求将会失败。
-
哪一行触发了错误?
-
你能给我们一个MVCE吗?如果它是一个 Rails 引擎,那么引擎应该正确安装在一个虚拟应用程序中。
-
引擎已正确安装,因为其他路线工作正常。例如:post '/users/register' => 'users#create' 工作正常。
标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 routes