Questions tagged [paperclip]

Paperclip is a library for the Ruby on Rails framework which makes dealing with file attachments easier. In addition to dealing with standalone files, the library provides convenience methods for creating image thumbnails. Paperclip is now deprecated - the authors recommend using ActiveStorage (they have provided a migration guide)

Paperclip is now deprecated. The library authors recommend switching to ActiveStorage. They have provided a migration guide as well.

Paperclip is intended as an easy file attachment library for ActiveRecord. The intent behind it was to keep setup as easy as possible and to treat files as much like other attributes as possible.

For more information:

4288 questions
39
votes
1 answer

Paperclip image url

Phone_large Why is "?1238845838" added to the image path? How can I get my path/url without it?
Arwed
  • 1,755
  • 3
  • 16
  • 26
39
votes
8 answers

How show hide image in paperclip when no image present

How can I prevent the image tag that calls the associated image from displaying if no image is associated with the record? <%= image_tag @agent.avatar.url %> ...gives me the text "Missing" if there is no image associated with that agent. I want to…
neezer
  • 19,720
  • 33
  • 121
  • 220
38
votes
4 answers

Paperclip: How to store a picture in a Rails console?

I tried storing a local image in a rails console. Because I have many pictures in my local storage (I use crawler to download tons of pictures), I want to store them into a database, with the benefit of paperclip to do some image job, like thumbnail…
mlzboy
  • 14,343
  • 23
  • 76
  • 97
38
votes
1 answer

Simple cropping with Paperclip

I would like to crop images on upload using Paperclip to get square thumbs from the center of the original picture. I find out a method in documentation that seems to do exactly what I want: transformation_to(dst, crop = false) The problem is that I…
collimarco
  • 34,231
  • 36
  • 108
  • 142
37
votes
2 answers

How can I get url for paperclip image in to_json

I have a model that uses paperclip like this: has_attached_file :avatar, :styles => { :large => "100x100>" , :medium => "50x50>", :small => "20x20>" }, :default_url => '/images/missing-owner_:style.png' I'm exporting this model with to_json method…
Giancarlo Corzo
  • 1,976
  • 5
  • 24
  • 36
36
votes
2 answers

Get server file path with Paperclip

I'm using Rails with Paperclip to make a small file upload app. I would like to be able to return the file path on the server of the uploaded file once its done but I can't seem to work out how to get the path? Paperclip only seems to record the…
seadowg
  • 4,215
  • 6
  • 35
  • 43
34
votes
2 answers

Saving files using Paperclip without upload

I had a quick question. Is it possible to save a file without actually uploading it through a form? For example, let's say I'm looking at attachments from emails, and I want to save them using a paperclip. How do I do this? Do I manually have to…
Punit Rathore
  • 970
  • 1
  • 8
  • 16
33
votes
10 answers

Default_url in Paperclip Broke with Asset Pipeline Upgrade

I'm using Paperclip and have a default_url option like this for one of my attachments: :default_url => '/images/missing_:style.png' The asset pipeline obviously doesn't like this since the directories moved. What's the best way to handle this? I…
yellowreign
  • 3,528
  • 8
  • 43
  • 80
33
votes
3 answers

Rails Paperclip: update vs. update_attributes

I realized something quite strange when attempting to upload an image via the paperclip gem for my user model (under the avatar attribute). For some reason there User.update and @user.update_attributes behaves differently. Does anyone know why this…
Derrick Mar
  • 1,021
  • 1
  • 12
  • 15
33
votes
3 answers

unit test in rails - model with paperclip

I'm trying to write a test for a model with a picture, using paperclip. I'm using the test framework default, no shoulda or rspec. In this context, how should I test it? Should I really upload a file? How should I add a file to the fixture?
VP.
  • 5,122
  • 6
  • 46
  • 71
31
votes
7 answers

How do you access the raw content of a file uploaded with Paperclip / Ruby on Rails?

I'm using Paperclip / S3 for file uploading. I upload text-like files (not .txt, but they are essentially a .txt). In a show controller, I want to be able to get the contents of the uploaded file, but don't see contents as one of its attributes. …
Geoff
  • 9,470
  • 13
  • 52
  • 67
31
votes
6 answers

Saving the images Dimensions (width and height) in Paperclip?

Any Paperclip wizards out there know if you can when using Paperclip to save an image, also save the image dimensions (width and height) in 2 extra fields? How do you get such data during the Paperclip upload process?
TheExit
  • 5,220
  • 12
  • 37
  • 49
30
votes
5 answers

AWS::S3::S3Object.url_for - How to do this with the new AWS SDK Gem?

I've been using this forever with paperclip and aws-s3: def authenticated_url(style = nil, expires_in = 90.minutes) AWS::S3::S3Object.url_for(attachment.path(style || attachment.default_style), attachment.bucket_name, :expires_in =>…
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
30
votes
2 answers

Trying to get Paperclip to refresh or reprocess not working

I have over time, changed the size for thumbs of the class Deal. Through these changes, users were uploading to the site, so there are few people who have different sized thumbs. I wanted to reprocress or refresh these, so I went to into my root and…
Trip
  • 26,756
  • 46
  • 158
  • 277
28
votes
3 answers

undefined method `stringify_keys'

When I try to upload image using Paperclip gem I got this error: NoMethodError (undefined method `stringify_keys' for ) class MenuItem < ActiveRecord::Base has_one :image end class Image <…
user908798
  • 688
  • 4
  • 12
  • 16