2012-12-19 14 views
6

रेल पर रूबी में, मैं 2 आंशिक अपडेट करने की कोशिश कर रहा हूं।आंशिक प्रस्तुत करने के साथ पोस्ट प्रतिक्रिया जिसमें घटनाएं काम नहीं कर रही हैं

show.html.erb:

<div id="filters"><%= render :partial => "pricelistfilters" %></div> 

pricelistfilters.html.erb:

<% @properties.each do |prop| %> 
    #Render the page on properties (and the newproperties) 
    #<select ...><option>...</option><option>...</option> 
    #</select> 
<% end %> 

products.js -> आंशिक गाया

के लिए घटनाओं
$(window).ready(function(){ 
    selectionchanges(); 
}); 
function selectionchanges(){ 
    $('#filters select').change(function(){ 
    //Doing stuff to send with ajax 

    //Ajax: 
    $.ajax({ 
     url: document.URL, 
     type: 'POST', 
     data: params 
    }); 
    }); 
} 

products_controller.rb -> कोड में परिवर्तन पर कार्रवाई करने के

def show 
    #Changing the properties (and the pricelist properties) 
    @properties #is filled 
    @newproperties #is filled 
    respond_to do |format| 
    format.html 
    format.js 
    end 
end 

show.js.erb बनाया

$('#filters').html('<%= escape_javascript(render :partial => "pricelistfilters") %>'); 
selectionChanges(); 

मेरे गाया आइटम पूरी तरह से अच्छा है। हालांकि, जब मुझे प्रस्तुत आइटम के साथ उचित प्रतिक्रिया मिली है, तो यह अब AJAX नहीं भेजता है। तो मेरे चुने हुए आइटमों पर घटना समाप्त हो गई है, जबकि मुझे यकीन है कि मैंने उन्हें "selectchanges();" मेरी show.js.erb फ़ाइल के अंत में?

क्या कोई इसे हल कर सकता है?

अभिवादन और अग्रिम धन्यवाद

+0

कोड ब्लॉक अजीब व्यवहार कर रहे थे: धन्यवाद @jdl मेरी मदद करने के लिए! – ReBa

+0

आपका स्वागत है। मुझे आशा है कि आपको अपनी समस्या का अच्छा जवाब मिल जाएगा। – jdl

+3

आपके पास 'चयन परिवर्तन' और 'चयन परिवर्तन' है, क्या यह एक टाइपो है? – RadBrad

उत्तर

2

, product.js पर jQuery के लाइव समारोह का उपयोग कर के रूप में bellow का प्रयास करें:

$(window).ready(function(){ 
    selectionchanges(); 
}); 
function selectionchanges(){ 
    $('#filters select').live('change', function(){ 
    //Doing stuff to send with ajax 

    //Ajax: 
    $.ajax({ 
     url: document.URL, 
     type: 'POST', 
     data: params 
    }); 
    }); 
} 

मूल रूप से, आप HTML डोम के तत्व यह है कि आप पहली बार के लिए बाध्य बदल रहे हैं घटना 'परिवर्तन' करने के लिए। तत्व के साथ, लाइव के साथ भी, jQuery आपके लिए बाध्यकारी फिर से करेगा।

उम्मीद है कि यह मदद करता है!

+0

इसे एक देखना चाहिए था। पूरी तरह से काम करना! धन्यवाद दोस्त। – ReBa