I am trying to create a rails API for an iphone application. Devise works great for web-based login, but I need to be able to create and destroy sessions using the REST API, and I want to use JSON instead of doing POST on the session controller and parse the HTML and handle the redirection.
I thought I could do something like this:
class Api::V1::SessionsController < Devise::SessionsController def create super end def destroy super end end
and in config / routes.rb I added:
namespace :api do namespace :v1 do resources :sessions, :only => [:create, :destroy] end end
rake routes show that the routes are configured correctly:
api_v1_sessions POST /api/v1/sessions(.:format) {:action=>"create", :controller=>"api/v1/sessions"} api_v1_session DELETE /api/v1/sessions/:id(.:format) {:action=>"destroy", :controller=>"api/v1/sessions"}
When I send POST to / user / sessions, everything works fine. I get HTML and 302.
Now, if I get POST in / api / v1 / sessions, I get:
Unknown action AbstractController :: ActionNotFound
curl -v -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST http://localhost:3000/api/v1/sessions -d "{'user' : { 'login' : 'test', 'password' : 'foobar'}}"
authentication ruby ruby-on-rails devise
Akshay Kumar Feb 01 2018-11-11T00: 00Z
source share