2014-11-03 140 views
1

我嘗試使用下面的寶石'simple_token_authentication'但我得到以下錯誤undefined method acts_as_token_authentication_handler_for' for DevicesController:Classthis問題建議,這是一個缺乏寶石的問題然而simple_token_authentication是我的Gemfile,我已經運行bundle updatebundle install確認1.6版.0的寶石已安裝並重新啓動服務器。Simple_token_authentication路由錯誤

有點困惑幫助讚賞!

控制器

class DevicesController < ApplicationController 
    acts_as_token_authentication_handler_for User 

    def index 
    @devices = GpsDevice.all 
    render json: @devices 
end 
end 

用戶模型

class User < ActiveRecord::Base 
    acts_as_token_authenticatable 

    devise :database_authenticatable, :registerable, 
    :recoverable, :rememberable, :trackable, :validatable 
    end 

route.rb

Rails.application.routes.draw do 
    devise_for :users 
    match 'trackers', to: 'devices#index', via: 'get', :defaults => { :format => 'json' } 
end 

可以是或可以不是relev螞蟻我使用rails-api而不是導軌

謝謝!

回答

3

添加到您的ApplicationController:

extend SimpleTokenAuthentication::ActsAsTokenAuthenticationHandler 

或者使用的ApplicationController :: Base的。