Active Admin passwords allowed

Is there a way to tell if I am in create or edit mode inside an active admin's allow_params block? I would like to combine created_by and updated_by when I create a new record. When I edit an existing post, I only want to merge the update_by.

Here's my code:

ActiveAdmin.register Group do
  menu parent: "Groups", priority: 0

  permit_params do
    permitted = [:name, :description, :group_type_id, :owner_user_id]
    permitted.merge!(updated_by: current_admin_user)
    permitted
  end

      

I would like to say something like:

permitted.merge!(created_by: current_admin_user) if new_record?

      

new_record? is an active admin method, but it only works on forms.

Any ideas?

+3


source to share


1 answer


You can also combine it in the create and update action:



controller do
  def create
    params[:group].merge!(created_by: current_admin_user)
    create!
  end

  def update
    params[:group].merge!(updated_by: current_admin_user)
    update!
  end

end

      

+10


source







All Articles