Skip to content
This repository has been archived by the owner on Aug 17, 2017. It is now read-only.

Set polymorphic association in a manner that Rails picks up on the association add #236

Open
noahmatisoff opened this issue Feb 19, 2016 · 0 comments

Comments

@noahmatisoff
Copy link

I have a line in one of my models that looks like this:

has_many :notes, as: :notable, dependent: :destroy, after_add: :create_informal_note

I am sending a POST request to my Rails endpoint with JSON like this:

{
  "note": {
    "text": "Test note",
    "notable_id": 1,
    "notable_type": "AnotherModel"
  }
}

Rails & strong_parameters has no problem interpreting this and creating the data. However, due to the way the JSON request body is structured, Rails & strong_parameters simply just set the id and type fields.

This results in Rails not picking up on the added association, causing my after_add association callback not to trigger.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant