10

I have a session controller which inherits from Devise::SessionsController:

class SessionsController < Devise::SessionsController

  skip_before_filter :authenticate_user!, :only => [:get_token]

  def create
   ....
  end

 def destroy
  ...
 end

 def get_token
   response.headers["app-key"] = form_authenticity_token()
   render :text=>'Token Set'
 end

end

As you can see above i am overwriting create and destroy action and i have added another action named get_token. I added routes for it as shown below:

Routes.rb

Application.routes.draw do

  devise_for :users, :controllers => { :sessions => "sessions" }, :path => "users",      :path_names => { :sign_in => 'login', :sign_out => 'logout',:confirmation => 'verification'}

  match 'get_token', :to => 'sessions#get_token'

But I am getting the following errror when i am trying to access get_token method;

[Devise] Could not find devise mapping for path "/get_token". 

How to add route for the get_token action.

Thanks in advance

1 Answer 1

21

You need to scope the route in Devise like so:

devise_scope :user do
  get 'get_token' => 'sessions#get_token'
end

That should allow you call http://your-url/get_token to access that action.

1
  • I am getting Routing Error: uninitialized constant SessionsController for above. Any idea ?
    – CAK
    Commented Mar 27, 2017 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.