问题描述:

Could someone help me understand the following error message (when testing) and why when making a post request to my registrations controller create action I am using /lnf.json

In my routes I have the following constraints and path setup

constraints(subdomain: 'api') do

devise_for :users, path: 'lnf', controllers: { registrations: "registrations" }

end

And my Registrations Controller

class RegistrationsController < Devise::RegistrationsController

skip_before_action :verify_authenticity_token

respond_to :json

def create

super

end

end

If i make a post request via curl to http://api.local.dev:3000/lnf.json I get the response I require.

When I want to test this using rspec i have a simple test setup

post :create, format: :json, :user => {user params here}

But i get an error when running the test

AbstractController::ActionNotFound:

Could not find devise mapping for path "/lnf.json?

Could anyone help me understand whats going on here please.Keen to understand it.

Thanks

EDIT

Output of rake routes as requested

 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"}

registrations controller

 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"}

网友答案:

it looks like devise_for routes part need tune a little bit (or add special route for your case with lnf aka "post '/lnf', to: 'registrations#create', defaults: {format: 'json'}"). could you please put output of 'rake routes | grep devise' command here?

相关阅读:
Top