Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 参数[:令牌]未使用设备设置_Ruby_Devise_Token_Params - Fatal编程技术网

Ruby 参数[:令牌]未使用设备设置

Ruby 参数[:令牌]未使用设备设置,ruby,devise,token,params,Ruby,Devise,Token,Params,我正在尝试实现Desive,但还不熟悉 当我请求…/api/v1/projects.json时,我得到了“undefined method admin?”?对于nil:NilClass',我假设发生这种情况是因为未设置参数[:token]: class Api::V1::ProjectsController < Api::V1::BaseController def index respond_with(Project.for(current_user)) end end

我正在尝试实现Desive,但还不熟悉

当我请求…/api/v1/projects.json时,我得到了“undefined method admin?”?对于nil:NilClass',我假设发生这种情况是因为未设置参数[:token]:

class Api::V1::ProjectsController < Api::V1::BaseController
  def index
    respond_with(Project.for(current_user))
  end
end
class Api::V1::ProjectsController
--
class项目
--
class用户
--
class Api::V1::BaseController

有人知道如何/在何处使用designe设置params[:token]吗?

显然我误解了文档,token是通过URL传入的: …/api/v1/projects.json?token=s28seWhpPVWkhMU7sszM

我想问题解决了

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