我有一个会话控制器,它继承自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
如上所示,我覆盖了创建和销毁操作,并添加了另一个名为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'
但是当我尝试访问get_token方法时,我得到以下错误信息;
[Devise] Could not find devise mapping for path "/get_token".
如何为get_token操作添加路由。
提前致谢
答案 0 :(得分:20)
您需要在Devise中确定路线范围,如下所示:
devise_scope :user do
get 'get_token' => 'sessions#get_token'
end
这应该允许您致电http://your-url/get_token来访问该操作。