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 on rails 如何使用带有Grape的\u http\u令牌进行身份验证\u或\u请求\u?_Ruby On Rails_Ruby_Curl_Grape_Grape Api - Fatal编程技术网

Ruby on rails 如何使用带有Grape的\u http\u令牌进行身份验证\u或\u请求\u?

Ruby on rails 如何使用带有Grape的\u http\u令牌进行身份验证\u或\u请求\u?,ruby-on-rails,ruby,curl,grape,grape-api,Ruby On Rails,Ruby,Curl,Grape,Grape Api,如何在grapeapi中使用\uhttp\u令牌实现authenticate\u或\urequest\u。下面是我的代码: module Articles class ArticleData < Grape::API include ActionController::HttpAuthentication::Token::ControllerMethods # http_basic do |email, password| # u

如何在grapeapi中使用\uhttp\u令牌实现authenticate\u或\urequest\u。下面是我的代码:

module Articles 
    class ArticleData < Grape::API
        include ActionController::HttpAuthentication::Token::ControllerMethods
     #   http_basic do |email, password|
        #   user = User.find_by_email(email)
        #   user && user.valid_password?(password)
        # end

        before do
            error!("401 Unauthorized", 401) unless authenticated
        end

        helpers do
            def authenticated
                 authenticate_or_request_with_http_token do |token, options|
                    apiKey = ApiKey.where(auth_token: token).first
                     #ApiKey.exists?(access_token: token)
                 end
            end
        end

        resource :article_data do

            desc "Return all article data"
            get do
                Article.all
            end

            desc "create a new article"
            ## This takes care of parameter validation
            params do
                requires :title, type: String
                requires :author, type: String
                #requires :content, type: Text
            end

            #This takes care of creating article
            post do
                Article.create!({
                    title:params[:title],
                    content:params[:content],
                    author:params[:author],
                    user_id:params[:user_id],
                    image_url:params[:image_url]
                })
            end

            desc "update article"
            # this takes care of parameter validation
            params do
                requires :image_url, type: String
            end

            put ':id' do
                Article.find(params[:id]).update({
                    content:params[:content],
                    image_url:params[:image_url]
                })
            end

            desc "delete article by id"
            # this takes care of parameter validation
            params do 
                requires :id, type: String
            end

            delete ':id' do
                Article.find(params[:id]).destroy!
            end

        end

    end
end
模块文章
类ArticleData

当我运行curl命令:curl时,我得到了这个错误NoMethodError(未定义的方法'authenticate_或'u request_with#u http_token'):。任何帮助都将不胜感激。提前感谢。

显示您的应用程序控制器。