Active Admin: Customize only new form Active Admin: Customize only new form ruby-on-rails ruby-on-rails

Active Admin: Customize only new form


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 :Submitend

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 -%>


I am not sure it can be done directly with form. If you take a look at the code you'll see that only the last call is taken into account. On the other hand, you may try something like:

config.set_page_config :new do  form :partial => 'form'end

But I would rather ask the developers for this feature.