I'm using Ember with ember-data and a rails api. I had a createRecord() and save() for the record that was working fine. The payload in the network tab for the post request to create the record in rails looks like: {data: {attributes: { foo: 'bar' } }
.
In the rails controller, I have strong params like so: params.require(:data).require(:attributes).permit(:foo)
, which was working fine for a little while. Now when I send the request rails says that param is missing or the value is empty: data
. If I look in the network tab in the browser the payload for the request still looks the same as stated above. If I puts params
it only shows {"controller": "api/v1/answers", "action": "create"}
and isn't showing the data payload at all.
Is there any reason why rails isn't picking up on the right params from ember now? I did try to add an association to the model that I'm trying to create, which is when it started failing. However, I rolled back to when it was working, but it's not working anymore.
I fixed this by going into the config/initializers/mime_types.rb
file in the rails api and changing the file to look like:
api_mime_type = %W(
application/vnd.api+json
text/x-json
application/json
)
Mime::Type.unregister :json
Mime::Type.register 'application/json', :json, api_mime_type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With