简体   繁体   中英

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

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).

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'. 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:

form :partial => "a"

In this contrived example 'a' is my A class so replace it where necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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