Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 560
jriff Avatar asked Feb 19 '23 19:02

jriff


1 Answers

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
like image 180
John Servinis Avatar answered Feb 27 '23 03:02

John Servinis