-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
POST to API Endpoint has Empty Params #28564
Comments
Hi there, please create an executable failing test case using https://github.com/rails/rails/blob/master/guides/bug_report_templates/action_controller_gem.rb as a template so that others can reproduce and help you solve the issue. |
You need to add the following line to |
Just wanted to follow up @vipulnsward and @ngn01 really appreciate this response. Worked successfully, and helped me understand the relationships among everything. |
Since we are using this Rails app as API only. There was an error preventing the params to be access in the controller. The reason was that due to the MIME type, the request was throwing a 500 error. The fix was to register the type MIME `application/vnd.api+json` so that `content_type` header has the correct type. Another error preventing was the relationship constrain of `user_id` unable to be `nil` for `topic.user_id` which was address in the controller method `create`. This was a temporary change for the `@topic.user_id = 1` which we will change as soon as we are able to. related: * https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types * rails/rails#28564
Params is set but the request payload is being lost.
Request Headers
Raw Payload
{"data":{"attributes":{"first-name":"Test","last-name":"User","email":"lkjlkj@kjhjk.com"}}}
Controller
If I set up the same app using Rails 4.2.6/Ruby 2.3.3, this works perfectly with no changes in the payload, so it looks like it's something with the way Rails 5 handles requests, potentially?
I should also mention that the source URL is test.lvh.me:4200 (an ember app) to the Rails API test.lvh.me:3000, so CORS may play a role here in stripping the params? I'm not receiving any error as the headers appear correct and CORS is set up here to allow any origin via Rack::Cors middleware.
Rails version:
Rails 5.0.1
Ruby version:
Ruby 2.3.3
The text was updated successfully, but these errors were encountered: