Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Active Admin: Customize only new form

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 
like image 310
Michael Irwin Avatar asked Jul 17 '11 16:07

Michael Irwin


2 Answers

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.

like image 55
ryanb006 Avatar answered Oct 04 '22 15:10

ryanb006


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 -%> 
like image 32
Michael Irwin Avatar answered Oct 04 '22 14:10

Michael Irwin