Rails 4 : unknown attribute: shared_attachments_attributes for accepts_nested_attributes_for -


मॉडल / पार्टनर_टैक्टमेंट.आरबी

  वर्ग प्रतिभागी अटैचमेंट & lt; ActiveRecord :: बेस belongs_to: प्रतिभागी has_many: shared_attachments validates_presence_of: accepts_nested_attributes_for लगाव: shared_attachments, reject_if: all_blank, allow_destroy: सच अंत  

मॉडल / shared_attachment.rb

 < कोड> क्लास शेडएक्टैक्टमेंट & lt; ActiveRecord :: बेस belongs_to: प्रतिभागी belongs_to: participant_attachment अंत  

shared_attachment.html.haml

 % उल - @ participants.each करना | भागीदार | = Hidden_field_tag ​​'participant_attachments [shared_attachments_attributes] [] [participant_attachment_id]', @ attachment.id बचाव नहीं के बराबर% ली% लेबल = participant.full_name = check_box_tag "participant_attachments [shared_attachments_attributes] [] [participant_id]", participant.id, @ shared_participants.include (participant.id.to_s)  

participant_attachments_controller.rb

  डीईएफ़ create_shared_participants shared_participants = SharedAttachment.new (activity_params) shared_participants.save अंत डीईएफ़ activity_params पैरामीटर। की आवश्यकता होती है (: participant_attachments) .permit (: participant_id,: लगाव, shared_attachments_attributes: [: participant_id,: participant_attachment_id]) अंत  

मैं अधिक चेकबॉक्स 'मूल्यों accespts_nested_attributes_for का उपयोग कर बचाने के लिए कोशिश कर रहा हूँ। ? "Authenticity_token" "✓", { "UTF8" = & gt: लेकिन अज्ञात विशेषता की तरह हो रही त्रुटि:

  पैरामीटर: shared_attachments_attributes.any समाधान  

यहां लॉग है = & gt; "efwsP0tQksCSQqwqoH2qJwANJ / OFChQviG + 4Kz8SYgI =", "participant_attachments" = & gt; { "shared_attachments_attributes" = & gt; [{ "participant_attachment_id" = & gt; "14", "participant_id" = & gt; "2"}, { " participant_attachment_id "= & gt;" 14 "," participant_id "= & gt;" 4 "}]}} पूरे 500 आंतरिक सर्वर त्रुटि 15ms ActiveRecord :: UnknownAttributeError में (अज्ञात विशेषता: shared_attachments_attributes): एप्लिकेशन / नियंत्रक / भागीदार / participant_attachments_controller.rb: 34: में `create_shared_participants '

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

समस्या को आपके form_for तत्व में fields_for सहायक का सही ढंग से उपयोग नहीं करने का सबसे अधिक परिणाम होता है।

आमतौर पर, जब आप एक स्वीकार करता है _ नामित_एटीएडिट_डेट्स_ के लिए तर्क i N अपने मॉडल , आप अपने नियंत्रक / मॉडल को fields_for के साथ सापेक्ष डेटा पास कर देंगे, उन्हें अपने हाथ से सेट न करें:

 < कोड> # ऐप / नियंत्रक / भागीदार- संपर्क / नियंत्रक। आरबी क्लास पार्टिसिपेंट अटैचमेंट कंट्रोलर & lt; ApplicationController डीईएफ़ नई @participants = ParticipantAttachment.all @participant_attachment = ParticipantAttachment.new @ participants.each करते @ participant_attachment.shared_attachments.build अंत अंत अंत # एप्लिकेशन / विचारों / participant_attachments / new.html.erb के & lt;% = form_for @participant_attachments करना | च | & Gt%; & Lt;% = f.fields_for: साझा_ैटकैट्स do | sa | & Gt%; & Lt;% = sa.text_field: participant_id% & gt; & Lt;% = sa.text_field: participant_attachment_id & lt;% end% & gt; & Lt;% end% & gt;  

यह स्वचालित रूप से आपको "नेस्टेड" मॉडल विशेषताओं के 3 सेट देगा, जिसे आप अपने मॉडल में भेज सकेंगे।

मुझे यकीन नहीं है अगर यह आपकी समस्या को सीधे हल करेगा, लेकिन मुझे पता है कि आप यह सुनिश्चित करने के लिए क्या चाहिए होना चाहिए कि आप अपना आवेदन सही तरीके से कार्य कर पा रहे हैं


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -