【发布时间】:2015-03-10 09:59:25
【问题描述】:
我如何理解以下错误消息(在测试时)以及为什么在向我的注册控制器创建操作发出发布请求时,我使用的是/lnf.json?
在我的路线中,我有以下约束和路径设置
constraints(subdomain: 'api') do
devise_for :users, path: 'lnf', controllers: { registrations: "registrations" }
end
还有我的注册控制器
class RegistrationsController < Devise::RegistrationsController
skip_before_action :verify_authenticity_token
respond_to :json
def create
super
end
end
如果我通过 curl 向http://api.local.dev:3000/lnf.json 发出帖子请求,我会得到所需的响应。
当我想使用 Rspec 进行测试时,我有一个简单的测试设置
post :create, format: :json, :user => {user params here}
但我在运行测试时遇到错误
AbstractController::ActionNotFound:
Could not find devise mapping for path "/lnf.json?
编辑
按要求输出 Rake 路由
new_user_session GET /lnf/sign_in(.:format) devise/sessions#new {:subdomain=>"api"}
user_session POST /lnf/sign_in(.:format) devise/sessions#create {:subdomain=>"api"}
destroy_user_session DELETE /lnf/sign_out(.:format) devise/sessions#destroy {:subdomain=>"api"}
user_password POST /lnf/password(.:format) devise/passwords#create {:subdomain=>"api"}
new_user_password GET /lnf/password/new(.:format) devise/passwords#new {:subdomain=>"api"}
edit_user_password GET /lnf/password/edit(.:format) devise/passwords#edit {:subdomain=>"api"}
PATCH /lnf/password(.:format) devise/passwords#update {:subdomain=>"api"}
PUT /lnf/password(.:format) devise/passwords#update {:subdomain=>"api"}
user_confirmation POST /lnf/confirmation(.:format) devise/confirmations#create {:subdomain=>"api"}
new_user_confirmation GET /lnf/confirmation/new(.:format) devise/confirmations#new {:subdomain=>"api"}
注册控制器
cancel_user_registration GET /lnf/cancel(.:format) registrations#cancel {:subdomain=>"api"}
user_registration POST /lnf(.:format) registrations#create {:subdomain=>"api"}
new_user_registration GET /lnf/sign_up(.:format) registrations#new {:subdomain=>"api"}
edit_user_registration GET /lnf/edit(.:format) registrations#edit {:subdomain=>"api"}
PATCH /lnf(.:format) registrations#update {:subdomain=>"api"}
PUT /lnf(.:format) registrations#update {:subdomain=>"api"}
DELETE /lnf(.:format) registrations#destroy {:subdomain=>"api"}
lnf POST /lnf(.:format) registrations#create {:subdomain=>"api", :format=>"json"}
【问题讨论】:
标签: ruby-on-rails ruby json rspec devise