I am trying to create a custom nested form in RailsAdmin for one of my models to add more functionality than the built in widget allows.
I have a Project that has_many TechSpecs. In my rails_admin.rb initializer I have the following
config.model Project do
edit do
configure :tech_specs do
partial 'tech_specs_field'
end
end
end
In _tech_specs_field.html.haml (I’m personally more comfortable with erb but I get very odd “no method safe_concat for nil:NilClass” errors unless I use haml) I have
= form.fields_for(field.name) do |nested_form|
= render :partial => 'spec', :locals => {:nested_form => nested_form}
- add = "<i class='icon-plus icon-white'></i> New Tech Spec".html_safe
= form.link_to_add add, field.name, { :class => 'btn btn-info' }
I can actually see the blueprint for new tech_specs generated on the page in a hidden div at the bottom but clicking the New Tech Spec button does nothing. Inside _spec.html.haml is just a bunch of text_fields and hidden_fields plus the remove link (which does work).
I’m wondering two things:
1) How can I track down what should be happening in JS and fix it or my partial to work with the RailsAdmin nested forms from the bbenezech-nested_form gem (which RailsAdmin depends on)
2) Any ideas as to why my partial had to be in haml other than it’s what RailsAdmin uses and somehow it is incompatible in the massive chain generating the admin form?
This isn’t a good final answer but I was able to get around the problem with the following JS hack in ui.js
On custom partials where I want to use a nested form, I simply add the ‘no_tabs’ class to their containing div and reuse the original insertFields method from bbenezech-nested_forms.