0

I am integrating Cocoon to add multiple attachment with my property object.

But when I am creating new property record, I am getting ArgumentError: wrong number of arguments (2 for 1) error

= form_for @property, remote: true, authenticity_token: true, html: { class: "form-horizontal", multipart: true } do |f|
 .links
   = link_to_add_association 'Add', f, :attachments
 .modal-footer
   .actions
     %button.btn.btn-default{"data-dismiss" => "modal", :type => "button"} Close
     = f.submit 'Save',  class: 'btn btn-warning'

/gems/cocoon-1.2.9/lib/cocoon/view_helpers.rb i.e. before new_object = create_object(f, association, force_non_association_create)

[1] pry(#<#<Class:0x0000000b46f630>>)> create_object(f, association, force_non_association_create)

ActionView::Template::Error (wrong number of arguments (2 for 1)):
   1: = form_for @property, remote: true, authenticity_token: true, html: { class: "form-horizontal", multipart: true } do |f|
   2:   .links
   3:     = link_to_add_association 'Add', f, :attachments
   4:   .modal-footer
   5:     .actions
   6:       %button.btn.btn-default{"data-dismiss" => "modal", :type => "button"} Close
 app/views/properties/_form.html.haml:3:in `block in _app_views_properties__form_html_haml___4571956341154479101_90407280' 

from /home/dev05/.rvm/gems/ruby-2.2.2@me_backend/gems/activerecord-4.2.5.1/lib/active_record/attribute_methods/query.rb:35:in `attribute?'

I have models

class Property < ActiveRecord::Base
 has_many :attachments, as: :attached_item, dependent: :destroy
 accepts_nested_attributes_for :attachments,allow_destroy: true
end

class Attachment < ActiveRecord::Base
 belongs_to :attached_item, polymorphic: true
end

Gem versions

rails version '4.2.5.1'
ruby version '2.2.2'
cocoon (1.2.9)

Gemfile.lock file snapshot

activerecord (4.2.5.1)
   activemodel (= 4.2.5.1)
   activesupport (= 4.2.5.1)
   arel (~> 6.0)  rails (4.2.5.1)
   actionmailer (= 4.2.5.1)
   actionpack (= 4.2.5.1)
   actionview (= 4.2.5.1)
   activejob (= 4.2.5.1)
   activemodel (= 4.2.5.1)
   activerecord (= 4.2.5.1)
   activesupport (= 4.2.5.1)
   bundler (>= 1.3.0, < 2.0)
   railties (= 4.2.5.1)
   sprockets-rails

Can someone please help me to identify that what is causing issue to not creating the attachment.

Vik
  • 5,931
  • 3
  • 31
  • 38
  • This is confusing: you have a `property` which `:has_many :attachments`, you are editing/creating properties, what does the sentence "Its working fine when I am not using the associated property object." --> how can you use it _without_ the property object? The first error can only occur during rendering of the view; Did you overwrite initializers are `after_create` callback? And the second errors seems to indicate turbolinks problem? – nathanvda Aug 30 '17 at 12:11
  • Thanks @nathanvda, Have modify the problem, but I did not get your mean for first point "Did you overwrite initializers are after_create callback?", Can you please explain a bit more, that where you are asking to overwrite. – Vik Aug 31 '17 at 07:24
  • Normally this code just works, so I was asking if you did something abnormal in your model (like overwrite the initializer or add a `after_create` callback?) which might cause that error. Do you get the error when rendering the form? Can you show the complete call-stack? – nathanvda Aug 31 '17 at 14:27
  • Yes it seems ti be an easy and there is no callbacks into the property model, and we are just getting error when rendering form. ActionView::Template::Error (wrong number of arguments (2 for 1)): 1: = form_for @property, remote: true, authenticity_token: true, html: { class: "form-horizontal", multipart: true } do |f| 2: .links 3: = link_to_add_association 'Add', f, :attachments 4: .modal-footer 5: .actions 6: %button.btn.btn-default Close app/views/properties/_form.html.haml:3:in `block in _app_views_properties__form_html_haml___4571956341154' – Vik Sep 04 '17 at 07:45
  • Please add call-stack to your question, so you can sort it correctly, this is unreadable. If all else would you be able to produce a small repo on github that reproduces the problem? Then i will take a look. – nathanvda Sep 04 '17 at 09:15
  • Thanks @nathanvda, Have added stacktrace please have a look. – Vik Sep 04 '17 at 14:04
  • That is not the complete stacktrace? I only see one line? – nathanvda Sep 07 '17 at 07:31

0 Answers0