Questions tagged [paperclip-validation]
89 questions
4
votes
3 answers
Conditional paperclip presence verification
How can I verify a paperclip attachment does not exist if another field does exist? I tried:
validates_attachment :img, presence: false, if: :some_other_field?
def some_other_field?
some_other_field
end

lwiseman
- 750
- 7
- 29
4
votes
2 answers
Ruby/Rails inheritance, overriding validators defined in super-class in sub-class
I have the following rails/paperclip validator:
class ImageRatioValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
attr_name = "#{attribute}_width".to_sym
value = record.send(:read_attribute_for_validation,…

luxerama
- 1,109
- 2
- 14
- 31
3
votes
0 answers
Paperclip attachment size validation fails, but size is valid?
My model
class Article < ActiveRecord::Base
LOGO_TYPES = ['image/jpeg', 'image/png', 'image/gif']
VALID_LOGO_MESSAGE = 'Please attach a valid picture file containing your organization logo. Valid formats are JPG, PNG, and GIF'
…

Allyl Isocyanate
- 13,306
- 17
- 79
- 130
3
votes
3 answers
paperclip validations causing Error in Rails 3
I've recently installed the paperclip gem to my Rails 3 app. I am trying to allow users to upload an avatar to their profile. I followed the install instructions and here is what my models/views look like:
My 'user.rb' model has the following code:…

slovak_100
- 782
- 2
- 10
- 33
3
votes
1 answer
paperclip content type for xls and xlsx
struggling with paperclip content type, need to upload xls/xlsx file.
has_attached_file :sheet
validates_attachment_content_type :sheet, content_type: [
…

Anuj
- 1,737
- 3
- 16
- 29
3
votes
1 answer
Rails 4, Paperclip 4.2.1 give error with binary file upload
I have following setup with rails 4 and paperclip 4.2.1
class Post< ActiveRecord::Base
has_attached_file :key
allowed_content_type = ['text/plain',
'text/rtf',
'text/richtext',
'application/txt',
'application/octet-stream']
…

user1570144
- 479
- 3
- 17
3
votes
0 answers
Paperclip size validation error message displayed twice
In redemption_image.rb,
class RedemptionImage < ActiveRecord::Base
belongs_to :business, :touch => true
has_attached_file :display_image, :url => "/system/:class/:attachment/:id_partition/:hash.:extension",
…

Sakshi Jain
- 410
- 5
- 21
3
votes
1 answer
Rails paperclip attachment validation failure with .ogg format
this is my first post on stackoverflow. I'm developing a rails app which require a song model that has an .ogg audio file attached by paperclip. I'm using .ogg format due to some browsers audio formats restrictions.
Unfortunately, when creating a…

Prade Mismo
- 229
- 2
- 13
3
votes
1 answer
Paperclip Content Type Validation Failing in Rspec
I'm using Rails 4.0.0 with Paperclip 4.1.1 for attaching mp3 and pdf files. I'm writing my integration tests in Rspec with Capybara.
I have content type and file name validations in place for both types of files.
class Song <…

Taylor714
- 2,876
- 1
- 15
- 16
3
votes
1 answer
no validates_attachment_file_name when upgrading to Paperclip 4.1 from 3.5
We have code that looks like run of the mill paper clip:
has_merchants_attached_file :pdf,
storage: :s3,
s3_credentials: Mbc::DataStore.s3_credentials,
s3_permissions: :private,
path: …

Noah Clark
- 8,101
- 14
- 74
- 116
3
votes
2 answers
Is it possible to make an attachment optional in paperclip?
Here's how I am using paperclip in my model:
has_attached_file :photo,
styles: {
display: {
geometry: "146x153#",
format: :jpg,
},
message: {
geometry: "48x48#",
format: :jpg,
}
…

geeku
- 65
- 9
3
votes
1 answer
Checking file size/type before upload using Paperclip and Rails
I have a Rails app which allows users to upload videos (on a local, rather than a cloud, server).
I'm using Paperclip 3.1.4 and Paperclip-ffmpeg 0.9.0.
Everything is working fine and dandy, but the problem is that, if a user uploads a file in the…

Graeme
- 481
- 6
- 20
3
votes
3 answers
Paperclip file size validation error message
validates_attachment_size :image, :less_than => 5.megabytes
gives an error message of
Image file size must be less than 5242880 Bytes
This isn't very user friendly.. Is there a way to make the message to be
Image file size must be less than 5 MB…

Nick Ginanto
- 31,090
- 47
- 134
- 244
3
votes
1 answer
Paperclip gives error when image is not uploaded
Paperclip works fine when I upload an image and then display it with:
<%= image_tag @post.photo.url(:medium) %>
The problem is, if an image wasn't uploaded, I get this error:
NoMethodError in Posts#show
Showing…

user1779563
- 770
- 3
- 7
- 13