custom setter for association not being called #1422

Closed
brewster1134 opened this Issue Dec 3, 2012 · 4 comments

Comments

Projects
None yet
2 participants
Contributor

brewster1134 commented Dec 3, 2012

I noticed something odd when updating an object via rails_admin. This is totally contrived example.

class Project
  include Mongoid::Document
  has_many :categories
  field :name
  attr_accessible :category_ids, :name

  def category_ids= ids
     puts 'category_ids CALLED!'
  end

  def name= name
     puts 'name CALLED!'
  end
end

class Category
  include Mongoid::Document
  belongs_to :project
  field :name
  attr_accessible :name
end

RailsAdmin.config do |config|
  config.model Project do
    edit do
      field :name
      field :categories do
        orderable true
      end
    end
  end
end

when i run my tests (or via console), both setters are called.

--> p = Project.new()
--> p.assign_attributes({ name: 'foo', category_ids: [] })
name CALLED!'
category_ids CALLED!'
=> {}

however when i save the project via rails_admin, only name= is called.

name CALLED!

Processing by RailsAdmin::MainController#edit as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"xxx", "project"=>{"category_ids"=>["", "", "50bb09f8b9b4f3831b00000a"]}, "return_to"=>"http://localhost:3000/admin/project", "_add_edit"=>"", "model_name"=>"project", "id"=>"50bb09f8b9b4f3831b000019"}

Any ideas here? Im burnt out on debugging!

Contributor

brewster1134 commented Dec 13, 2012

I picked this issue up again. Still not finding a solution but I updated the example above to show that non-association custom setters are being called through rails_admin, just not the custom has_many setter.

Contributor

brewster1134 commented Jan 16, 2013

For me, this issue prevents any custom ordering of associated objects since the parent never calls the association's setter method to properly update the position fields (as mentioned in the wiki). To make sure it was not my app, i created a new rails project with a barebones setup here. The issue exists in this new app as well.

https://github.com/brewster1134/rails_admin_1422

Can someone please confirm that im not crazy?! This seems like a big issue that would effect many users. Thanks!

Contributor

brewster1134 commented Feb 8, 2013

still an issue with the latest gem. are issues still actively addressed?!

Collaborator

mshibuya commented May 6, 2013

Fixed by #1509.

mshibuya closed this May 6, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment