Paperclip and ImageMagick and a Weird Problem — in RoR
As promised in the last post, here is the Paperclip and ImageMagick as an extension to railstutorial.
For image upload and manipulation, Paperclip seems to be the solutions. The following links does a great job of describing the installation process and basic usage, so I have nothing to add here.
- Paperclip: Attaching Files in Rails (don’t use SVN, use git repo instead as in the second link below)
- Goodbye attachment_fu, hello Paperclip
- http://railscasts.com/episodes/134-paperclip
- The Ruby On Rails Paperclip Plugin Tutorial – Easy Image Attachments
- Ruby On Rails Polymorphic Paperclip Plug-in Tutorial
So far so good, but if you are following railstutorial, you will probably doing this stuff to micropost, and you will probably get an error like this,
- “missing” image replacement in microspots
- In the log/development.log file,
Rendering rescues/layout (not_found)
Solution:
If you carefully inspect the log file you can catch the line
[4;36;1mMicropost Create (0.4ms)[0m [0;1mINSERT INTO “microposts” (“created_at”, “photo_file_size”, “updated_at”, “photo_file_name”, “photo_content_type”, “user_id”, “photo_updated_at”, “content”)
Just with just one line, open your model and fix the accessibility:
class Micropost & ActiveRecord::Base attr_accessible :content, :photo ...
ps. In case you are a noob like me in RoR, this link shows howto uninstall the paperclip plug in.
ps2. Another possible problem might be your ImageMagick installation, make sure you have the correct path by trying convert and identify command. In case add the path to development.rb as described this Stackoverflow entry.
Summary of Steps to add Paperclip
- script/plugin install git://github.com/thoughtbot/paperclip.git
- script/generate paperclip product photo
- In the model
has_attached_file :photo
- In the form
header part
<% form_for @micropost do |f| %>
<% form_for @micropost, :html => { :multipart => true} do |f| %>
body part
<p> <%= f.file_field :photo %> </p>
- To show the uploaded file
<%= image_tag @product.photo.url %>






Trackbacks & Pingbacks