I finally decided to replace all my existing code to handle images with Paperclip. I was following the screencast by Emerson Lackey, #134 Paperclip, however I ran into a couple of issues. Thankfully they were all very easily fixed, and probably wouldn’t have occurred at all if I’d simply watched the whole screencast instead of trying to rush on ahead.
The first issue I encountered was that my asset fields weren’t appearing on the page:
I spent way too much time trying to work this one out, especially considering how obvious the solution is – the screencast is simply missing an “=” after the initial “<%" in "<% f.fields_for". Simply amend it as follows:
The second one is actually encountered and addressed by Emerson himself. Unfortunately I started trying to find a solution before seeing his, so just in case someone else does a Google search I’ll include the issue here:
undefined method `symbolize_keys!' for "/system/assets/1/original/mack_truck.jpg?1329550205":String
The problem here is simply that the parenthesis are in the wrong place, simply amend your code as follows:
Anyway, hopefully this helps someone else out – let me know if there are any issues.
Update: Don’t name your model assets!
Unfortunately I followed the tutorials naming example and called my model Asset. While this may have been fine in earlier version of rails it causes quirky conflicts with the asset pipeline. I strongly encourage you to use a different name i.e. Uploads
Leave a Reply