Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Nested has_many duplicated partial #924

Closed
pollingj opened this Issue · 8 comments

3 participants

John Polling Benoit Bénézech kazik
John Polling

I'm probably doing this wrong, so apologies if I'm being dumb.

I have a model offers which has_many images. I've setup the model like this

has_many :offer_images, dependent: :destroy, inverse_of: :image_offer

accepts_nested_attributes_for :offer_images, allow_destroy: true
attr_accessible :offer_images_attributes, allow_destroy: true

I also have my rails_admin initialiser setup like this

    edit do
      group :default do 
        field :title, :string
        field :description, :text
        field :offer_date, :date
        field :offer_images do
          help 'Required'
        end
      end
      group :tagging do
        field :tag_list, :tag_list
        field :brands, :has_and_belongs_to_many_association do
          partial "brands_selector"
        end

      end
    end

This gives me the Offer Images option with 'Add New' button, however when I press the 'Add New' button it show 2 offer_image fields, and if I press the 'Add New' button again the same thing happens. The 'Delete' button for each instance also fails. Have I missed something obvious in my config?

Thanks
John

Benoit Bénézech
Collaborator

Do you have gem 'nested_form' in your Gemfile ?

If so, you should remove it and use the included version instead.

John Polling

Nope, afraid not.

I also did a gem list to double check and the only nested_form gem I have is this one

bbenezech-nested_form (0.0.2)

kazik

I have the same problem as @pollingj.

Having associations set up as follows:

class Rejection < ActiveRecord::Base
  belongs_to :rejectable, :polymorphic => true
end

class Photo < ActiveRecord::Base
  has_many :rejections, :as => :rejectable
  accepts_nested_attributes_for :rejections
  attr_accessible :rejections_attributes
end

when editing photo through rails_admin and clicking 'add new' button next to rejections, two rejection nested forms show up. Additionaly 'remove' button does not work on any of them. The problem occurs for any nested association. I havn't changed default config inside rails_admin initializer. I also don't have nested_form gem in my Gemfile or anywhere in project's gem list.

John Polling

In the I switched to activeadmin, but only because the client asked for a load of additional changes that were easier to sort in activeadmin. However, I did spot that when I was running this on production the above problem didn't occur, even though it did in development.

Benoit Bénézech
Collaborator

Somehow, it looks like the asset pipeline is messing up with you guys.
I'm interested if you can investigate a bit to see what's causing it.

kazik

Thanks guys for your responses! You are right bbenezech - I was not using asset pipeline the right way. I was precompiling assets on development and commiting them into repository. That was causing various problems. So I've removed public/assets and I'm doing assets precompiling only during deployment. Everything works fine now.

John Polling

sorry, meant to say....yep, that's pretty much the problem I was having as well :)

Benoit Bénézech
Collaborator

Ok, closing then.

Benoit Bénézech bbenezech closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.