ruby on rails - update_attributes() does not works properly -


  @ related = book.find_all_by_related (@ book.related) अगर @ related.count & gt; 1 @ related.each दो | बी | B.update_attributes (params [: पुस्तक]) अंत का अंत  

मैं रेल 2.3.5 का उपयोग कर रहा हूँ। उपरोक्त कोड के लिए, पहले चलना ठीक काम करता है और सही दिखाता है। लेकिन अगली यात्रा के लिए, b.update_attributes () झूठे दिखाता है। सभी पैरामीटर पुनरावृत्तियों में पहुंच रहे हैं विधि update_attributes () क्या कोई शर्त है?

यदि आपके मॉडल को attr_accessible विशेषताओं निर्दिष्ट किया गया है, तो केवल उन विशेषताओं को अपडेट किया जाएगा ।

एट्रिएबल का इस्तेमाल उपयोगकर्ताओं को एट्रिब्यूट्स के बड़े पैमाने पर असाइनमेंट (उपयोगकर्ता द्वारा) को रोकने के लिए करें, जो उपयोगकर्ता द्वारा संपादन योग्य नहीं होना चाहिए। मास असाइनमेंट का उपयोग आपके मानक नियंत्रक के बनाने और अद्यतन तरीकों में किया जाता है।

  वर्ग उपयोगकर्ता & lt; ActiveRecord :: बेस attr_accessible: login,: password end  

तो, निम्न करने से ख़ुशी से सच वापस आ जाएगा, लेकिन स्थिति विशेषता को अद्यतन नहीं करेगा।

  @ User.update_attributes (: स्थिति = & gt; 'सक्रिय')  

यदि आप स्थिति विशेषता को अपडेट करना चाहते हैं, तो आपको उसे अलग से असाइन करना चाहिए।

  @ User.status = 'सक्रिय' सहेजें  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -