Custom form in Active Admin

I am creating a custom form in Active Admin 0.5. I registered the page and created the form via 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 I submit the form, I get empty Params hashes. And the form tag does not contain an authentication token.

What am I doing wrong?

+4
source share
2 answers

Old post, but for those who stumbled upon this problem, the answer is to add

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

to form. This returns an authentication token on ActiveAdmin so that it can confirm that the fake did not succeed. Your session was terminated and you were returned to the login screen because ActiveAdmin thought you were trying to fake the view.

Your form should 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 
+6
source

I use the following syntax with forms AA (with f.inputs do block) Also you should use object property names for inputs

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

Hope this helps!

+1
source

Source: https://habr.com/ru/post/1440557/


All Articles