Reputation: 2893
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).
Upvotes: 4
Views: 5016
Reputation: 2893
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.
Upvotes: 4