ciembor
ciembor

Reputation: 7337

Different forms for update and create actions in ActiveAdmin

Is it possible to have different forms for update and create actions in ActiveAdmin? How could I achieve this? I was looking for this for a while in documentation and I can't find anything.

Upvotes: 1

Views: 880

Answers (2)

Nguyen
Nguyen

Reputation: 2123

You can use object.new_record? to check if the record is new or not.

For example:

    form do |f|
      if object.new_record? # new 
        f.inputs do
          f.input :name
          f.input :age
        end    
      else                  # update
        f.inputs do
          f.input :name
        end
      end

      f.actions
    end

Upvotes: 2

usha
usha

Reputation: 29349

Of course you can

def new
end

def edit
end

def create
end

def udpate
end

And in your new template, have the form for create and in your edit template, have the form for update. When the user clicks on add new, hook it to new action. When the user clicks on update, hook it to edit

new.html.haml/new.html.erb

<form for create>

edit.html.haml/edit.html.erb

<form for update>

Upvotes: 0

Related Questions