2

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
Christian-G
  • 2,371
  • 4
  • 27
  • 47
  • Not really sure to understand but this [question](http://stackoverflow.com/q/9944065/5006469) may help you. – rdupz Mar 21 '16 at 16:53

0 Answers0