I'm debugging carrierwave. It's fun. I think the problem comes down to this:
Inside carrierwave_direct, there's this code:
if record.new_record? && record.send("has_#{attribute}_upload?") && record.key !~ record.send(attribute).key_regexp
The #key_regexp code is this:
/\A#{store_dir}\/[a-f\d\-]+\/.+\.(?i)#{extension_regexp}(?-i)\z/
which evaluates to this when I am debugging:
record.send(attribute).key_regexp
/\Astories\/\/main_images\/[a-f\d\-]+\/.+\.(?i)(jpg|jpeg|gif|png)(?-i)\z/
My store_dir is this:
"stories/#{model.id}/main_images"
and I think there's a blank "/" section because model.id is nil.
The record.key is this:
"/stories/main_imagescache/20160319-1549-2202-5826/blueapronimage.jpg"
Why doesn't it currently match?
It looks like the regex has an extra slash and I'm not sure what this section is:
[a-f\d\-]+\/.+\.(?i)(jpg|jpeg|gif|png)(?-i)
Is it any number of letters between a-f, digit, or "-", then a "/", then any number of letters or numbers, then a "."....
What is the (?i)?
What are capture groups?
What is the (?-i)?
I think this is the problem:
record.key !~ /\Astories/
true
It should be false.