I want to save images from a url via a form that populates a "Select" field with a number of options. When the form is submitted, the selected image should be saved with the Paperclip gem.
Here is the html select code block:
<select id="story_medium" name="story[medium]">
<option data-img-src="http://www.somedomain.com/image0.jpg" value="0">http://www.somedomain.com/image0.jpg</option>
<option data-img-src="http://www.somedomain.com/image1.jpg" value="1">http://www.somedomain.com/image1.jpg</option>
<option data-img-src="http://www.somedomain.com/image2.jpg" value="2">http://www.somedomain.com/image2.jpg</option>
</select>
The problem is that when I set the form input as you would usually do with Paperclip, in this case as ":medium", I get an error that says "ActiveRecord::AssociationTypeMismatch at /stories Medium expected, got String". This seems to be because I am passing the option value as a string, rather than an integer.
Parameters: { "story"=>
{"url"=>"http://www.somedomain.com/image2.jpg",
"title"=>"Title of Image",
"medium"=>"2",
"commit"=>"Submit"}
If I change ":medium" to ":medium_id", the form saves without an error, however, only the key value is saved, and Paperclip does not save the image from the specified url.
How can I pass the value of the image url in the form action so that it properly saves with Paperclip?
Rails 4.1.8, Paperclip 4.2.1, ruby 2.1.5p273