The goal: User selects either a avatar image for upload and clicks "Upload" or clicks "Reset" to remove the custom avatar image and use default. (The underlying forms, controller, action, model are the same except for the "picture" field is hidden in the non-working form.)
1- When the user selects an image, the form submit works and carrierwave uploads the image. Here's the working version submit action hash:
<%= f.file_field :picture, accept: 'image/jpeg,image/gif,image/png' %>
Hash {"utf8"=>"✓", "_method"=>"patch",
"authenticity_token"=>"xxxxx",
"avatar"=>{"picture"=>#<ActionDispatch::Http::UploadedFile:0x2e77fd8
@tempfile=#<File:C:/DOCUME~1/Val/LOCALS~1/Temp/RackMultipart20150305-2620-
1pq50l5.png>, @original_filename="admin_foodler_profile.png",
@content_type="image/png", @headers="Content-Disposition: form-data;
name=\"avatar[picture]\";
filename=\"admin_foodler_profile.png\"\r\nContent-Type: image/png\r\n">},
"commit"=>"Upload photo", "controller"=>"avatars", "action"=>"update",
"user_id"=>"8"}
2- When the user selects to replace avatar with default, here's the non-working submit action hash.
<%= f.hidden_field :picture, value:'default_profile.png' %>
Hash {"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"xxxx",
"avatar"=>{"picture"=>"default_profile.png"}, "commit"=>"Reset profile image",
"controller"=>"avatars", "action"=>"update", "user_id"=>"8"}
When I use the hidden field on the form with the default image name, as you see in the hash. "picture" is just the filename, it's not the upload method, but I don't know why. But as a result ActionDispatch is not invoked and the default image is not uploaded nor is the table updated.
I'm pretty sure there is a simple answer, and that the hidden attribute "picture" field is the culprit. But I'd really like to offer users the ability to simply switch their avatar for the default png. I thought this would be a no-brainer change. Hah. Suggestions much appreciated.