Posts tagged as:

paperclip

Watermarking images paperclip’s post-processor

April 8, 2009

No Gravatar

For those of you who wanted to use thoughtbot’s paperclip plugin to manage image uploads but were having trouble watermarking said images, behold!

http://github.com/ng/paperclip-watermarking-app/tree/master

{ Comments }

Paperclip deletes images with empty file fields update with rails 2.3

March 5, 2009

No Gravatar

Bahhh! When you update a model that contains an empty file field in Rails 2.3 the attachment is deleted. It looks like empty file fields get passed as nil and then Paperclip gets angry.

Processing Admin::PostsController#update (for 127.0.0.1 at 2009-03-05 01:21:08) [PUT]
  Parameters: {"commit"=>"Update", "post"=>{"title"=>"Post Title", "image"=>nil}, "id"=>"124"}

There are two quick monkey patches that I’ve been using, the first, was splitting off attachments to their own method (edit_attachment)…but this quickly became a nuisance. A quicker work around is to remove the attachment field, in this case “image”, from the parameters.

 
# PUT /posts/1
# PUT /posts/1.xml
def update
  @post = Post.find(params[:id])
 
  # delete the offending parameter
  params[:post].delete(:image) if params[:post][:image].nil?
 
  respond_to do |format|
    if @post.update_attributes(params[:post])
      flash[:notice] = 'Post was successfully updated.'
      format.html { redirect_to(admin_post_url(@post)) }
    else
      format.html { render :action => "edit" }
    end
  end
end

{ Comments }

Paperclip not saving your images?

March 2, 2009

No Gravatar

I’ve had a few guys email me asking if I had any idea why Paperclip wasn’t saving their uploaded images. Here’s a form one of them sent me:

<% form_for(@post) do |f| %>
  <%= f.error_messages %>
 
 
    <%= f.label :title %>
    <%= f.text_field :title %>
 
 
 
    <%= f.label :description %>
    <%= f.text_area :description %>
 
 
  <%= f.file_field :image %>
 
 
    <%= f.submit "Update" %>
 
 
<% end %>

Notice anything different on this form?

<% form_for(@post, :html => { :multipart => true }) do |f| %>
  <%= f.error_messages %>
 
 
    <%= f.label :title %>
    <%= f.text_field :title %>
 
 
 
    <%= f.label :description %>
    <%= f.text_area :description %>
 
 
  <%= f.file_field :image %>
 
 
    <%= f.submit "Update" %>
 
 
<% end %>

Simple mistake, but I’ve done it a few times in the early AM and wondered WTF was going on!

:html => { :multipart => true

{ Comments }

Paperclip doesn’t accept multiple files in Rails 2.3

February 17, 2009

No Gravatar

Those of you who have upgraded to Rails 2.3 may have encountered a bug where Thoughtbot’s Paperclip doesn’t want to accept multiple file attachments. I checked my models, migrations, and forms but I couldn’t figure it out for the life of me.

It turns out there is some kind of bug with the Rack interface that is wonky in 2.3. By updating to edge Rails I was able to fix this little bug.

{ Comments }