2012-05-03 7 views
11

मुझे यकीन है कि मैंने कुछ गलत कर रहा हूँ यहाँ हूँ, लेकिन यह है कि क्या अपने आवेदन नियंत्रक लग रहा है जैसे:मूल प्रमाणीकरण

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

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

मैं समझ नहीं क्यों मेरे http_basic_authenticate_with फेंक है यह त्रुटि:

undefined method `http_basic_authenticate_with' for ApplicationController:Class 

मुझे यकीन है कि यह कुछ आसान है, लेकिन मुझे यह नहीं दिख रहा है। MimeResponds अन्य नियंत्रकों में बस ठीक काम कर रहा है।

+0

क्यों आप से विरासत में मिली applicationcontroller actioncontroller :: एपीआई? –

+0

यह [रेल-एपीआई मणि] का उपयोग कर रहा है (https://github.com/spastorino/rails-api) – thatmiddleway

उत्तर

16

इसके बजाय विधियों को उपलब्ध कराने के लिए आपको ActionController::HttpAuthentication::Basic::ControllerMethods शामिल करना होगा। Here's the module in ActionController::Base

+0

कार्लोस, धन्यवाद, लेकिन अगर मैं कक्षा आवेदन नियंत्रक करता हूं shacker

4

आप एक रेल एपीआई है, तो अपने नियंत्रक से जोड़ें:

include ActionController::HttpAuthentication::Basic::ControllerMethods

class YourController < ApplicationController 

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

मैं रेल 4.2.4 का उपयोग कर रहा है और मेरे ApplicationController:

class ApplicationController < ActionController::API