The route for user actions in the controller, inheriting from Devise :: SessionsController

I have a session controller that 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 overwrite the create and destroy action, and I added another action called 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 get the following errror when I try to access the get_token method;

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

How to add a route for get_token action.

Thanks in advance

+8
ruby-on-rails routing devise
source share
1 answer

You need to specify the route in Devise as follows:

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

This will allow you to call http: // your-url / get_token to access this action.

+19
source share

All Articles