sferik/rails_admin — pull request #1726 by scarfaceDeb (2013-08-26 23:14:59+00:00)
Title: Add ability to inherit custom fields from RailsAdmin::Config::Fields::Association

I'm writing new custom field for globalize3 integration and I noticed that you get `undefined method [] for nil:NilClass` error due to empty `@properties` variable that `association` method returns in `label` method:
``` ruby
register_instance_option :label do
(@label ||= {})[::I18n.locale] ||= abstract_model.model.human_attribute_name association[:name]
end
```
`field.properties` instance variable is lost when rails_admin calls `configure` method inside edit block:
``` ruby
edit do
configure :translations, :globalize3_tabs
end
```
Inside `configure` method it calls `field` method, which removes this field from `_fields` array (because it's type hasn't found in default stack), and creates it again as my custom type.

In the process, it gets `properties` for this field from an `abstract_model.properties`, but it's `nil`, because it's not a model's property, but it's association.

But you can see inside `factory` method in `RailsAdmin::Config::Fields` that when it was creating default `has_many` field for this association, it was indeed using `abstract_model.associations`, instead of 'abstract_model.properties':
``` ruby
parent.abstract_model.associations.select{|a| a[:type] != :belongs_to }.each do |association| # :belongs_to are created by factory for belongs_to fields
# Unless a previous factory has already loaded current field as well
unless fields.find {|f| f.name == association[:name] }
# Loop through factories until one returns true
@@registry.find {|factory| factory.call(parent, association, fields) }
end
end
```

Also, I noticed that has_many field already had `properties` variable set before it was deleted and reinitialized.
So, I decided to use `field.properties` variable instead of `abstract_model.properties`.

---
I'm rather new to Ruby and Rails, that's why I'm writing my thought process in such details.
I hope I made myself clear and my English is not so terrible to read.)