简体   繁体   English

如何将自定义html或按钮添加到ActiveAdmin表单

[英]How to add custom html or buttons to ActiveAdmin form

I have models A and B. A has_many B. In the edit view for AI am displaying all of it's B children using 我有模型A和B. A has_many B.在AI的编辑视图中显示所有使用的B儿童

f.inputs  :for => :bs do |b|...

What I want to do is add a 'delete' link or button after ever B child of A. At the end of the list of B's I'd like to add a 'Add B' button which would create a new B instance and associate it with the current A. This way I can avoid an additional edit view for B (B is a very simple model). 我想要做的是在A的B子之后添加一个'删除'链接或按钮。在B列表的末尾我想添加一个'添加B'按钮,它将创建一个新的B实例和关联它与当前的A.这样我可以避免B的额外编辑视图(B是一个非常简单的模型)。

I figured it out. 我想到了。 I had to create a custom form partial. 我不得不创建一个自定义表单部分。 You do this by creating a file called 'app/views/admin/_as.html.erb'. 您可以通过创建名为“app / views / admin / _as.html.erb”的文件来完成此操作。 Here you can create you form like you would a normal view, starting with: 在这里,您可以像普通视图一样创建表单,从以下开始:

<%= semantic_form_for [:admin, @a] do |f| %>
...
<%= link_to 'Delete', admin_b_path, :id => b.object.id, :action => :destroy %>

Then in 'app/admin/as.rb' you just need to add the line: 然后在'app / admin / as.rb'中你只需添加一行:

form :partial => "a"

In this contrived example 'a' is my A class so replace it where necessary. 在这个人为的例子中,'a'是我的A类,所以在必要时替换它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM