I have a rails app with 3 models something like:
I'm trying to create a form to edit the join table (eg. change the appointment_date in the example model):
1 <%= semantic_form_for [:active_admin, :organization, @organization_membership] do |f| %>
2 <%= f.inputs "Organization" do %>
3 <h2><%= @organization_membership.organization.name %></h2>
4 <% @organization_membership.organization.organization_memberships.each do |organization_member| %>
5 <%= organization_member.user.name %></br>
6 <% end %>
7 <% end %>
8 <%= f.inputs "New Member" do %>
9 <span id="new-member"></span>
10 <% if !resource.user.nil? %>
11 <h3><%= resource.user.login %></h3>
12 <% end %>
13 <%= f.input :user_id, :as => :hidden, :input_html => { :id => 'user-id' } %>
14 <%= f.input :organization_id, :as => :hidden, :value => @organization_membership.organization.id %>
15 <%= f.input :start_date, :as => :date_picker %>
16 <%= f.input :end_date, :as => :date_picker %>
17 <% end %>
18 <%= f.actions %>
19 <% end %>
The problem is that this renders a page with the following html:
<form accept-charset="UTF-8"
action ="/active_admin/organizations/8/organization_memberships/8"
class ="formtastic organization_membership"
id ="edit_organization_membership_8"
method ="post"
novalidate ="novalidate">
The problem is the action
. It's should look like this:
/active_admin/organizations/:organization_id/organization_membership/organization_membership_id
But, instead of :organization_id
, formtastic is putting in the organization_membership_id
. I suspect that my problem is in the top line <%= semantic_form_for [:active_admin, :organization, @organization_membership]
.
EDIT: I've managed to get this "working" by extending the update()
method with the following ugly hack:
def update
params[:organization_id] = params[:organization_membership][:organization_id]
super
end
Still searching for a real solution to this problem.