I'm using Active Admin to provide an admin to some models. I need to provide a customized new form for one of them, but leave the edit form as the default provided by Active Admin. Here's what I have. It works in that it is giving me the new form I want, but the edit form is also using the new form, which is not what I want:
ActiveAdmin.register Document do form :partial => 'form' end
I've tried this, but it gives an error that 'new' is an undefined method:
ActiveAdmin.register Document do new do form :partial => 'form' end end
If you just want to hide or show certain fields on the new form (e.g. a field that you generate automatically in the model using before_create), you can do this:
form do |f| f.inputs "Member Details" do f.input :first_name f.input :last_name f.input :email if !f.object.new_record? f.input :password f.input :password_confirmation end end f.button :Submit end
This will hide the password fields when you create a new member in the event that you automatically generate passwords the first time the member is created.
I've figured out a way to do it with some logic in the view. Not the best way, to be sure, but it does what I want until I figure out a better way. Here's the logic I'm using:
<% if controller.action_name == 'new' %> new form <% else %> edit form <% end -%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With