2011-07-21 21 views
6

मैं अपने ऐप में प्रमाणीकरण का प्रबंधन करने के लिए डेविस और डेविसइवेबल के साथ काम कर रहा हूं और मुझे आमंत्रण नियंत्रक # अपडेट में AJAX समर्थन जोड़ने में कुछ परेशानी हो रही है। DeviseInvitable में नियंत्रक इस तरह दिखता है:"answer_with_navigational" कैसे काम करता है?

# invitations_controller.rb 

# PUT /resource/invitation                         
def update 
    self.resource = resource_class.accept_invitation!(params[resource_name]) 

    if resource.errors.empty? 
    set_flash_message :notice, :updated 
    sign_in(resource_name, resource) 
    respond_with resource, :location => after_accept_path_for(resource) 
    else 
    respond_with_navigational(resource){ render_with_scope :edit } 
    end 
end 

यह अच्छी तरह से काम करता है जब resource.errors.empty? == true और हम निष्पादित करें:

respond_with resource, :location => after_accept_path_for(resource) 

(अर्थात निमंत्रण/update.js.erb प्रदान की गई है और मेरे जावास्क्रिप्ट कॉल किए जाते हैं)। समस्या यह है कि जब resource.errors.empty? == false है, और हम निष्पादित करें:

respond_with_navigational(resource){ render_with_scope :edit } 

सर्वर बताता है:

Rendered invitations/update.js.erb (1.4ms) 

लेकिन मेरे जावास्क्रिप्ट कॉल रन नहीं किया जा रहा है। क्या कोई बता सकता है कि respond_with_navigational क्या करना चाहिए? मैं घंटों तक गुगल रहा हूं और मुझे कहीं भी इस एपीआई का स्पष्टीकरण नहीं मिला है।

धन्यवाद!

उत्तर

10

ठीक है, मुझे पता है कि respond_with_navigational क्या कर रहा है। यह इस तरह के रूप वसीयत आधार वर्ग में परिभाषित किया गया है:

def respond_with_navigational(*args, &block) 
    respond_with(*args) do |format| 
     format.any(*navigational_formats, &block) 
    end 
end 

और, navigational_formats रूप में अच्छी तरह वसीयत में परिभाषित किया गया है:

# Returns real navigational formats which are supported by Rails 
def navigational_formats 
    @navigational_formats ||= Devise.navigational_formats.select{ |format| Mime::EXTENSION_LOOKUP[format.to_s] } 
end 

तो, यह मूल रूप से respond_with() के लिए एक आवरण है। आदेश में इस काम करने के लिए पाने के लिए, मैं अपने InvitationsController के लिए निम्न जोड़ने के लिए किया था:

respond_to :html, :js 

और अब, update.js.erb ठीक से प्रदान की गई की जा रही है।

+0

इस उत्तर के कारण यहां आया: http://stackoverflow.com/a/9154096/18706 (यदि कोई इसका उपयोग करने का व्यावहारिक उदाहरण ढूंढ रहा हो)। – mahemoff

+0

इसके अलावा, यह डिफ़ॉल्ट प्रारंभकर्ता में एक विवरण है: https://gist.github.com/3824340 – mahemoff

संबंधित मुद्दे