Search code examples
ruby-on-rails-3activeadminformtastic

Rails Active Admin: Why isn't my custom form rendering any inputs?


Rails 3.1.1
Active Admin 0.4.4
formtastic 2.1.1

This is the active admin controller for my Agency model.

ActiveAdmin.register Agency do
  form do |f|
    f.input :name
    f.input :contact_email, :label=>"Email invoices to"
    f.input :api_key, :hint=>"Create a key by following <a href=\"#\" target=\"_blank\">these instructions</a>".html_safe
    f.actions
  end
end

The form should render the three inputs, followed by the submit button, but all I get is:

no inputs

Just to be clear, the HTML shows no signs of the missing inputs:

<form accept-charset="UTF-8" action="/admin/agencies" class="formtastic agency" id="agency_new" method="post" novalidate="novalidate" name="agency_new">
  <div style="margin:0;padding:0;display:inline">
    <input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="...">
  </div>
  <fieldset class="actions">
    <ol>
      <li class="action input_action" id="agency_submit_action">
        <input name="commit" type="submit" value="Create Agency">
      </li>
    </ol>
  </fieldset>
</form>

I also tried using fieldsets, with the same (faulty) output:

ActiveAdmin.register Agency do
  form do |f|
    f.inputs "New Agency" do 
      f.input :name
      f.input :contact_email, :label=>"Email invoices to"
      f.input :api_key, :hint=>"Create a key by following <a href=\"#\" target=\"_blank\">these instructions</a>".html_safe
    end
    f.actions
  end
end

Update: I've discovered that commenting out the f.actions line gets formtastic to actually print the inputs, but now just without the button.

ActiveAdmin.register Agency do
  form do |f|
    f.inputs "New Agecny" do 
      f.input :name
      f.input :contact_email, :label=>"Email invoices to"
      f.input :api_key, :hint=>"Create a key by following <a href=\"#\" target=\"_blank\">these instructions</a>".html_safe
    end

    #f.actions
  end
end

Form with inputs but no button:

no button


Solution

  • Try using this: f.buttons :submit

    I also think that the block for buttons/actions changed a bit in a version of active admin at some point, so you may be tripped up by old tutorials, etc.