jriff
jriff

Reputation: 1977

Custom form in Active Admin

I am creating a custom form in Active Admin 0.5. I have registered a page and created a form through the DSL:

ActiveAdmin.register_page 'Planning', :namespace => :pos_admin do

  content :title => proc{ I18n.t("active_admin.dashboard") } do

    form do |f|
      f.input :type => :text
      f.input :type => :submit
    end

  end
end

The problem is that when submitting the form I get an empty Params hash. And the form tag contains no authenticity token.

What am I doing wrong?

Upvotes: 4

Views: 12313

Answers (2)

John Servinis
John Servinis

Reputation: 269

An old post, but for anyone stumbling upon this issue, the answer is to add

f.input :name => 'authenticity_token', :type => :hidden, :value => form_authenticity_token.to_s

to the form. This passes the auth token back to ActiveAdmin so that it can confirm no forgery has taken place. Your session was being terminated and you were taken back to the login screen because ActiveAdmin thought you were trying to forge a submission.

Your form should now look like this

form do |f|
  f.input :name => 'authenticity_token', :type => :hidden, :value => form_authenticity_token.to_s
  f.input :type => :text
  f.input :type => :submit
end

Upvotes: 8

Fivell
Fivell

Reputation: 11929

I use next syntax with AA forms (with f.inputs do block) Also you have to use property names of object for inputs

 form do |f|
   f.inputs do
     f.input :property_name,  :type => :text
   end
   f.actions
  end

Hope it will help!

Upvotes: 0

Related Questions