Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with RailsAdmin. "The action 'new' could not be found for DeviseTokenAuth::SessionsController" #107

Closed
furkanayhan opened this issue Jan 9, 2015 · 7 comments

Comments

@furkanayhan
Copy link

I want to use RailsAdmin gem for my API application.

when I visit "localhost:3000/admin"
I get: The action 'new' could not be found for DeviseTokenAuth::SessionsController

my routes.rb

mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
mount_devise_token_auth_for 'User', at: '/api/v1/auth', skip: [:omniauth_callbacks]
namespace :api, defaults: { format: 'json' } do
  namespace :v1 do
    # resources...
  end
end

Ruby 2.2
Rails 4.2

@lynndylanhurley
Copy link
Owner

  1. Which version of this gem are you using?
  2. Does the discussion in Active_admin issue #47 help you out at all?

@furkanayhan
Copy link
Author

  • I am using 0.1.31.beta8
  • I have tried, but it did not help.

Can't I use Devise for web while using this gem?
How do I login in a browser, not via an API.

@lynndylanhurley
Copy link
Owner

You can use devise alongside this gem, but you will need to mount the routes to a different path.

For example:

Rails.application.routes.draw do

  # token auth routes available at /api/v1/auth
  namespace :api do
    scope :v1 do
      mount_devise_token_auth_for 'User', at: 'auth'
    end
  end

  # standard devise routes available at /users
  devise_for :users

end

@furkanayhan
Copy link
Author

Your routes.rb config fixes the route issue.

But there is a new problem now.

In Rails Admin panel, when I try to Log Out, it goes to /api/v1/auth/sign_out instead of /users/sign_out.
They are both defined in routes:

destroy_api_v1_user_session DELETE /api/v1/auth/sign_out(.:format)        devise_token_auth/sessions#destroy {:format=>"json"}
destroy_user_session DELETE /users/sign_out(.:format)              devise/sessions#destroy

Reason:

@lynndylanhurley
Copy link
Owner

Can this be solved by moving the devise_for method before the devise_token_auth_for method? For example:

Rails.application.routes.draw do

  # standard devise routes available at /users
  devise_for :users

  # token auth routes available at /api/v1/auth
  namespace :api do
    scope :v1 do
      mount_devise_token_auth_for 'User', at: 'auth'
    end
  end

end

@furkanayhan
Copy link
Author

And this works. Thank you! 👍

@lynndylanhurley
Copy link
Owner

🤘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants