2011-11-01 83 views
1

我試圖實現設計,但新的它。params [:令牌]沒有設置與設計

當我請求.../api/v1/projects.json時,我得到'undefined method admin?對於零:NilClass',這我假設是因爲PARAMS [:令牌]沒有被設置:

class Api::V1::ProjectsController < Api::V1::BaseController 
    def index 
    respond_with(Project.for(current_user)) 
    end 
end 

-

class Project < ActiveRecord::Base 
    ... 

    def self.for(user) 
    user.admin? ? Project : Project.readable_by(user) 
    end 
end 

-

class User < ActiveRecord::Base 
    before_save :ensure_authentication_token 

    devise :database_authenticatable, :registerable, :token_authenticatable, 
     :recoverable, :rememberable, :trackable, :validatable, :confirmable 
    ... 

end 

-

class Api::V1::BaseController < ActionController::Base 
    before_filter :authenticate_user 

    respond_to :json 

    private 

    def authenticate_user 
     @current_user = User.find_by_authentication_token(params[:token]) 
    end 

    def current_user 
     @current_user 
    end 

end 

有誰知道如何/在哪裏設置params [:token]與設計?

回答

0

顯然我誤解了文檔和令牌通過URL傳遞: .../API/V1/projects.json令牌= s28seWhpPVWkhMU7sszM

問題解決了,我想。