Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Route for custom action in controller inheriting from Devise::SessionsController

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

like image 224
Abhimanyu Avatar asked Oct 13 '11 10:10

Abhimanyu


1 Answers

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.

like image 194
janders223 Avatar answered Oct 21 '22 11:10

janders223