I use ajax to manage presentations into a Subscription
model. Each subscription can have many presentations. The presentations form lives as a separate form within the subscription form and uses remote=true
to perform the update.
When I do: insert, reload page, insert
nothing goes wrong. However, when I do: insert, insert
it will end up with three different records instead of two with one record being updated.
The code that is called by javascript is:
def update_properties
Subscription.skip_callback(:save, :after, :notify_observer)
if !subscription_params[:presentations_attributes].nil?
returns = @subscription.update_attributes(presentations_attributes: subscription_params[:presentations_attributes])
end
if returns
respond_to do |format|
format.html
format.js
end
end
end
@subscription
is taken from the method:
def set_subscription
@subscription = Subscription.find(params[:id])
end
The subscription_params
method:
def subscription_params
params.require(:subscription).permit(:role, presentations_attributes: [:id, :title, :presentation_id, :_destroy, :subscription_id])
end