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.
Removed the need for the React client to nest all fields under the top level dmp (e.g. send { title: 'foo' } instead of { dmp: { title: 'foo' } }
Commented out the React client's Content-Type header. Rails figures out what is being sent
Commented out the call to api.getFileDataURL in new.js. Rails was able to work with the File as it was sent via formData
Updated the new.js file so that the form fields match what is being sent back to rails so we can just send formData
Added 'dmproadmap_opportunity_number' to the Rails list of acceptable parameters
Updated cors config to allow a preflight 'options' request (although I don't think this was necessary)
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 ofContent-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
andid
. For exampleid="plan_title" name="plan[title]"
and then Rails gets these as nested parametersplan: { 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 thedmp[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.
dmp
(e.g. send{ title: 'foo' }
instead of{ dmp: { title: 'foo' } }
Content-Type
header. Rails figures out what is being sentapi.getFileDataURL
innew.js
. Rails was able to work with the File as it was sent viaformData
new.js
file so that the form fields match what is being sent back to rails so we can just sendformData