Issue with nested form and new version of rails_admin

451 views
Skip to first unread message

michael_h

unread,
Mar 19, 2012, 7:21:56 AM3/19/12
to rails...@googlegroups.com
Hi,

since I updated my version of rails_admin (I haven't updated in about 2 months) and started applying some control against mass-assignment, I am having trouble displaying nested fields in the Rails Admin interface.
I am using Rails 3.1.1 (ruby 1.9.3), and I have the following scenario:

Model 1: Trip
              has_many :transports, :dependent => :destroy        
              attr_accessible :trip_name, :transports_attributes
              accepts_nested_attributes_for :transports, :allow_destroy => true
 
Model 2: Transport
             belongs_to :trip
             attr_accessible :transport_mode, :departure_date, :arrival_date


When I browse the Admin interface, navigate to Trips and click on "Add new Trip", I get to fill in all details for the trip, but when I click on the "Add a new Transport" button, I can only see a new tab saying "Transport (new)". It actually does not show me any fields for that new Transport item.

I believe this has something to do with mass assignment. I have read the following, but I don't think I am missing anything in the above models.  - https://github.com/sferik/rails_admin/wiki/Mass-assignments-protection

Any advice?

Thanks in advance,

Michael

michael_h

unread,
Mar 26, 2012, 6:32:52 AM3/26/12
to rails...@googlegroups.com
I just found out that my example above works fine when using the following rails_admin gem declaration: 

gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git', :ref => 'dac2e551c5126226ae8823118059a14f4d4b6cb7'

but it does not when using the following hash (or later versions):

gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git', :ref => '60f26aab9536378d8c0bfde79a9a3ee472de02df'

The second hash is related to a "better nested form" update, but it seems to be the cause to the issue I am experiencing.


Any thoughts?

Thanks,

Michael

michael_h

unread,
Apr 1, 2012, 3:23:06 AM4/1/12
to rails...@googlegroups.com
Resolved the issue by first switching over to bbenezech-nested_form gem (from ryanb's version), since it is recommended for Rails Admin (see https://github.com/sferik/rails_admin/issues/1001#issuecomment-4839284).
I also fixed the following associations that i had in my Transport Model:

I had : 

# Transport Addresses
has_many :addresses, :class_name => "TransportAddress", :dependent => :delete_all
has_one :origin_address
has_one :destination_address

Changed it to:

# Transport Addresses
has_one :origin_address
has_one :destination_address

(each address inherits from TransportAddress model, which belongs to the Transport model)

Once I applied the above changes, I was able to see all of my nested form fields.


Michael
Reply all
Reply to author
Forward
0 new messages