4

I have models A and B. A has_many B. In the edit view for A I 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).

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The consensus here: "ActiveAdmin is really great… at first." I already said this on a similar question, but it seems completely backwards that you have to rewrite your forms outside the ActiveAdmin DSL if you want one line of custom markup…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.