CDLUC3 / dmptool

DMPTool version of the DMPRoadmap codebase
https://dmptool.org
MIT License
58 stars 13 forks source link

fix issue with react client post/put to drafts_controller.rb #492

Closed briri closed 1 year ago

briri commented 1 year ago

Hey @andrewebdev. There were some issues with the way the POST/PUT data was being sent to Rails.

First, the api.js had a hard coded header of Content-Type: application/x-www-form-urlencoded but the pages were sending JSON. This was causing Rails to not be able to interpret the body correctly. I discovered that we can just exclude that header and Rails will apparently figure it out for us.

I referenced this article to figure out what to do on the React side.

Second, Rails controllers have normally expect every form element to include a name and id. For example id="plan_title" name="plan[title]" and then Rails gets these as nested parameters plan: { title: 'value' }. I wasn't sure how to structure that properly in React though (I suspect that we might need to encode the name due to the brackets). Since I couldn't get the dmp[title] to work, I just removed the need for the top level 'dmp' completely.

Please feel free to modify any of the React JS changes.

github-actions[bot] commented 1 year ago
1 Error
:no_entry_sign:

Please include a CHANGELOG entry.

You can find it at [CHANGELOG.md](https://github.com/DMPRoadmap/roadmap/blob/main/CHANGELOG.md).

Generated by :no_entry_sign: Danger