However when I put the line:
var formData = <%= @s3_direct_post.fields.to_json.html_safe %>;
I get "SyntaxError: expected expression, got '<'"
I've seen advice on other similar questions to put quotes around the Ruby code like so:
var formData = '<%s3_direct_post.fields.to_json.html_safe %>';
but then the variable becomes the string
<%s3_direct_post.fields.to_json.html_safe %> instead of executing the Ruby and putting the result in a string.
FYI I'm following a tutorial (https://devcenter.heroku.com/articles/direct-to-s3-image-uploads-in-rails) so it's possible that I didn't set something up right.