I have a session controller which inherits from Devise::SessionsController:
我有一个继承自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:
如上所示,我覆盖了创建和销毁操作,并添加了另一个名为get_token的操作。我为它添加了路线,如下所示:
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;
但是当我尝试访问get_token方法时,我得到以下错误信息;
[Devise] Could not find devise mapping for path "/get_token".
How to add route for the get_token action.
如何为get_token操作添加路由。
Thanks in advance
提前致谢
1 个解决方案
#1
20
You need to scope the route in Devise like so:
您需要在Devise中确定路由范围,如下所示:
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.
这应该允许您调用http:// your-url / get_token来访问该操作。
#1
20
You need to scope the route in Devise like so:
您需要在Devise中确定路由范围,如下所示:
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.
这应该允许您调用http:// your-url / get_token来访问该操作。