activeadmin/arbre

Arbre duplicates form fields when inspecting model during production/debug

Closed this issue · 3 comments

Moved from activeadmin/activeadmin#4639

Description

I came across this problem when building this activeadmin addon aiming to customize default ActiveAdmin layout by using CaptureHelper methods.

I'm getting repeated form fields when inspecting or evaluating arbre components related to forms. I didn't had problems with anything else but forms. Seems related to Arbre but couldn't find the bug yet.

Versions

activeadmin 1.0.0.pre4
rails 5.0.0.1.
ruby 2.3.0p0

Steps to reproduce

Take any ActiveAdmin resource that has a form declaration in its DSL and add a puts self.inspect before closing the block. You will get the form fields duplicated.

Example

I'll use the default admin_user Resource as an example:

ActiveAdmin.register AdminUser do
  permit_params :email, :password, :password_confirmation

  index do
    selectable_column
    id_column
    column :email
    column :current_sign_in_at
    column :sign_in_count
    column :created_at
    actions
  end

  filter :email
  filter :current_sign_in_at
  filter :sign_in_count
  filter :created_at

  form do |f|
    f.inputs "Admin Details" do
      f.input :email
      f.input :password
      f.input :password_confirmation
    end
    f.actions
    puts self.inspect
  end

end

Go to the edit or new route and you will get something like this:

image

Calling inspect on an Arbre element will render the content as a string in the content method. The original form fields are added to the output buffer as they are defined; then the output of the call to inspect is added as a text_node to the form. That is causing the duplication of content. It is rendering the form as a string and then appending that string to the form.

What behavior was expected of inspect in this situation?

Good description, thanks @zorab47.

This is only a bug during the debugging, which is not resolvable without rebuilding arbre.
For this reason I close this issue.

Thanks @zorab47 for the comment. I was looking for a way to return the "rendered" version of the arbre element without sending the result to the output buffer. I need this to be optional. I'll try to workaround this issue somehow.

Thanks!