Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested has_many duplicated partial #924

Closed
pollingj opened this issue Jan 10, 2012 · 8 comments
Closed

Nested has_many duplicated partial #924

pollingj opened this issue Jan 10, 2012 · 8 comments

Comments

@pollingj
Copy link

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

@bbenezech
Copy link
Collaborator

Do you have gem 'nested_form' in your Gemfile ?

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

@pollingj
Copy link
Author

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
Copy link

kazik commented Feb 6, 2012

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.

@pollingj
Copy link
Author

pollingj commented Feb 6, 2012

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.

@bbenezech
Copy link
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
Copy link

kazik commented Feb 14, 2012

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.

@pollingj
Copy link
Author

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

@bbenezech
Copy link
Collaborator

Ok, closing then.

dparis pushed a commit to dparis/rails_admin that referenced this issue Feb 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants