My content management system uses Thoughbot’s Paperclip gem to attach photographs to the stories. Photos are uploaded first to the local server. Then the server will later upload the photographs to Amazon S3. The process is transparent and silent — too silent it turned out.
I had upgraded my Rails project to 2.3.4 and along with the upgrade, updated all the gems on the server. Everything was working great. After several weeks went by I went and looked at my server data and noticed something strange — all the new photographs were still being served by my local server and not by Amazon S3.
Unfortunately my background process which transferred the photographs to Amazon was failing. However, I didn’t program it to throw loud errors at me. Sure, I use hoptoad for notifying me if my main application failed. I just never implemented it into the uploader. It’s always the spot you least expect it.
The uploader’s log file shows:
ArgumentError: wrong number of arguments (5 for 4)
That’s not very helpful. A google search for the error plus “paperclip” revealed that paperclip 2.3.1 was the problem. Some people said I should drop back to paperclip 2.3.0. But that doesn’t sound very smart. Thoughtbot is constantly improving the code and it should be tracked.
Other websites pinned the problem on a conflict between the right_aws and aws-s3 gems. There were a multitude of suggestions on how to correctly load the gems, in a special order, to avoid the conflict. I tried these and nothing seemed to work. Paperclip refused to upload files to S3.
Finally I started reading the commit log for Paperclip. There between 2.3.0 and 2.3.1 is a lot of work with AWS::S3. After a while it dawned on me, they switched. They quit using right_aws and now use aws-s3 to exclusively upload content to S3.
So to everyone having this problem you have a simple solution.
In your environment file, remove any mention of right_aws and add the following gem declaration:
config.gem "aws-s3", :lib => "aws/s3"
That’s it. Problem solved.