Active Admin中的自定义表单 [英] Custom form in Active Admin
问题描述
我正在Active Admin 0.5中创建自定义表单。我已经通过DSL注册了一个页面并创建了一个表单:
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
问题是,提交表单时,我得到一个空的Params哈希。并且表单标签不包含真实性标记。
The problem is that when submitting the form I get an empty Params hash. And the form tag contains no authenticity token.
我在做什么错了?
推荐答案
旧帖,但是对于任何在此问题上遇到困难的人,答案是添加
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
到表单。这会将身份验证令牌传递回ActiveAdmin,以便可以确认未进行任何伪造。您的会话已终止,由于ActiveAdmin认为您正在尝试伪造提交内容,因此您被带回登录屏幕。
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
这篇关于Active Admin中的自定义表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!