do you know if is there a method to know if the image has been uploaded?
I mean, i have a Foo_Class, and this class can have an attached image, but its presence is not necessary. Is there a way to know if a particular instance of that class have the image or not?
Thanks!
If foo.image?
returns true, then file uploaded.
When you added Paperclip to your model you added paperclip specific rows, mine are
cover_file_name
cover_content_type
cover_file_size
cover_updated_at
Then I check whether it is nil or not
Foo_Class.cover_file_name.nil?
I think that the proper solution is to use the file?
method.
foo.image.file?
http://rdoc.info/github/thoughtbot/paperclip/Paperclip/Attachment#file%3F-instance_method
using exists? will do a request to the server to check if the file is there, which can be quite slow, especially if it's on a different server or on S3.
using foo.image_file_name.nil? is probably the same as file? under the covers, but ou don't want to dependant on the implementation of paperclip, which could someday change.
If this is in my model
has_attached_file :avatar, :styles => {:logo => "230x50>", :card_image => "180x50>"}
You can check if the image is uploaded for a user i.e @user
<%= @user.avatar.exists? %>
This will return boolean value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With