Search code examples
ruby-on-railsrspecrspec-railsrails-routingrails-api

No route matches?


I'm getting a "No route matches" exception in one of my tests (and using curl from the command line) one of my routes (POST /users/confirm). The curl's I've tried are as follows, neither of them work and receive the same exceptions outlined in the below notes:

curl -X POST -H "Content-Type: application/json; version=1" \
   -d '{ user: { "token":"1deb36b4e6a7ba6d9203" } }' \
   http://localhost:3000/appname/users/confirm

curl -X POST -H "Content-Type: application/json; version=1" \
   -d '{ "token":"1deb36b4e6a7ba6d9203" }' \
   http://localhost:3000/appname/users/confirm

enter image description here

My test is as follows. I have config.wrap_parameters = true in my /config/application.rb file...

enter image description here

Here is my User UsersController#confirm action along with my strong params. I params.require(:user).permit(:token) as opposed to simply params.permit(:token) because, as stated above, I have config.wrap_parameters = true in my /config/application.rb file...

enter image description here

This is my route entry...

enter image description here

Here is the output from rails routes (app name removed)...

enter image description here

I have config.wrap_parameters = true in my /config/application.rb file...

enter image description here

Oddly enough, if I change my params in my test to post :confirm, params: { token: @user.confirmation_token }, I get the following error instead: enter image description here

At a loss. Any thoughts?


Solution

  • It turns out I didn't need :token in my route after all. Changed it to this, and all is well:

    post '/appname/users/confirm/', to: 'users#confirm', as: 'appname_users_confirm'