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]與設計?