2012-05-03 5 views
11

Ich bin sicher, dass ich etwas falsch hier tue, aber das ist, was meine Anwendung Controller wie folgt aussieht:Grund Auth mit Schienen-api

class ApplicationController < ActionController::API                                                   
    include ActionController::HttpAuthentication::Basic                                                  
    include ActionController::MimeResponds                                                     

    http_basic_authenticate_with :name => "joeyjojo", :password => "shabadoo" 
end 

ich kann nicht herausfinden, warum meine http_basic_authenticate_with wurf Dieser Fehler:

Ich bin mir sicher, es ist etwas einfaches, aber ich sehe es nicht. Der MimeResponds funktioniert gut in anderen Controllern.

+0

Warum Sie erbte von Application actioncontroller :: api? –

+0

Dies ist mit der [Rails-Api-Edelstein] (https://github.com/spastorino/rails-api) – thatmiddleway

Antwort

16

Sie müssen stattdessen ActionController::HttpAuthentication::Basic::ControllerMethods einschließen, um die Methoden verfügbar zu haben. Here's the module in ActionController::Base

+0

Carlos, danke, aber wenn ich Klasse ApplicationController shacker

4

Wenn Sie eine Rails-API haben, fügen Sie diese an Ihre Steuerung:

include ActionController::HttpAuthentication::Basic::ControllerMethods

class YourController < ApplicationController 

    include ActionController::HttpAuthentication::Basic::ControllerMethods 
    http_basic_authenticate_with name: "username", password: "passwd123" 

Ich benutze Rails 4.2.4 und mein Application:

class ApplicationController < ActionController::API