paperclip

Make a field optional in rails

≡放荡痞女 提交于 2019-12-20 03:26:13
问题 I use paperclip to attach an avatar to users, which works fine but when a new user attempts to register it complains about the avatar bieng too small and not of the right type. This is how i validate my avatars: validates_attachment_size :avatar, :less_than => 1.megabytes validates_attachment_content_type :avatar, :content_type => ['image/jpeg', 'image/png', 'image/gif'] This is the error i get when i try to register. There were problems with the following fields: * Avatar file size file size

405 Error when trying to POST a file in rails

家住魔仙堡 提交于 2019-12-20 02:56:07
问题 I am using paperclip gem to upload a file to the database. When I select the file I want to upload and go to create it, the next page should redirect_to root path. Instead, I get "Method Not Allowed" in my browser. I open Dev Tools and the console says: Failed to load resource: the server responded with a status of 405 (Method Not Allowed) My logs look like: Started POST "/assets" for ::1 at 2015-08-20 10:41:11 -0400 and remains hooked until I go back to another page. Here is my controller

paperclip where to place the missing.png default image?

…衆ロ難τιáo~ 提交于 2019-12-19 19:45:45
问题 I use paperclip in my app, but my controller tests are failing because of: BlogsControllerTest#test_should_update_blog: Paperclip::AdapterRegistry::NoHandlerError: No handler found for "/images/original/missing.png" /Users/user/.rvm/gems/ruby-2.1.2/gems/paperclip-3.5.2/lib/paperclip/io_adapters/registry.rb:19:in `handler_for' /Users/user/.rvm/gems/ruby-2.1.2/gems/paperclip-3.5.2/lib/paperclip/io_adapters/registry.rb:29:in `for' /Users/user/.rvm/gems/ruby-2.1.2/gems/paperclip-3.5.2/lib

Paperclip process images only

霸气de小男生 提交于 2019-12-19 13:47:06
问题 I would like to use a single file-field for multiple formats. It was my understanding that Paperclip was smart enough to only scale images and leave other formats alone, but this doesn't seem to work for flv's (which returns imagemagick/identify-errors). Is there any way to help Paperclip a bit and explicitly setup specific formats to scale? UPDATE: Apparently, these errors are prevented with :whiny=>false (thanks fl00r), which works fine for regular uploads. However, what I'm trying to do

Install ImageMagick for paperclip gem in windows

混江龙づ霸主 提交于 2019-12-19 10:11:38
问题 I followed this guide to use paperclip http://railscasts.com/episodes/134-paperclip?language=en&view=asciicast it is all ok but note that to enable resizing you’ll need to have ImageMagick installed on your server. So how should i install ImageMagick ?? i have WINDOWS 8 and on the site http://www.imagemagick.org/ download does not work!!!! 回答1: It certainly works - you need to make sure of 2 things: You install the correct static version for your OS (32-bit vs 64-bit). The 32-bit (x86) will

Rails: Preventing Duplicate Photo Uploads with Paperclip?

筅森魡賤 提交于 2019-12-19 05:35:15
问题 Is there anyway to throw a validation error if a user tries to upload the same photo twice to a Rails app using Paperclip? Paperclip doesn't seem to offer this functionality... I'm using Rails 2.3.5 and Paperclip (obviously). SOLUTION: (or one of them, at least) Using Beerlington's suggestion, I decided to go with an MD5 Checksum comparison: class Photo < ActiveRecord::Base #... has_attached_file :image #, ... before_validation_on_create :generate_md5_checksum validate :unique_photo #... def

Rails: Preventing Duplicate Photo Uploads with Paperclip?

孤街醉人 提交于 2019-12-19 05:35:14
问题 Is there anyway to throw a validation error if a user tries to upload the same photo twice to a Rails app using Paperclip? Paperclip doesn't seem to offer this functionality... I'm using Rails 2.3.5 and Paperclip (obviously). SOLUTION: (or one of them, at least) Using Beerlington's suggestion, I decided to go with an MD5 Checksum comparison: class Photo < ActiveRecord::Base #... has_attached_file :image #, ... before_validation_on_create :generate_md5_checksum validate :unique_photo #... def

Create paperclip attachment from rmagick image

旧城冷巷雨未停 提交于 2019-12-18 23:16:05
问题 I have a problem to find a way to save an image created with RMagick in a paperclip attachment. imageList = Magick::ImageList.new imageList.new("images/apple.gif", "images/overlay.png") ... picture = imageList.flatten_images I am in a model that have an attached file has_attached_file :picture, :url => ..., :path => ... and i just want my image returned by imageList.flatten_images to be saved as the picture of my model. Does anyone know how to do it easily please? thanks 回答1: Let's see if

Validate extension in Paperclip - Ruby on Rails

隐身守侯 提交于 2019-12-18 21:19:16
问题 I've found that Paperclip can validate file content type, i.e. image/jpeg, but I want to specifically validate the extension. This is because I'm working with an obscure extension that won't get a consistent content type. Anyone know if this is doable, or a good way to do this? 回答1: Guess, there is no need to validate it with paperclip's method. You can rather use something like: has_attached_file :attachment validates_format_of :attachment_file_name, :with => %r{\.(docx|doc|pdf)$}i Edit:

How can I change the upload directory for paperclip on heroku to /tmp?

允我心安 提交于 2019-12-18 17:01:06
问题 I need to upload files and then parse them using paperclip? Currently it is uploaded in the /system folder, which isn't allowed in heroku. I don't need the uploads to be persistent...I parse it and then store them. So I'd like to be able to save into /tmp and then parse, and then let it get blown away later. Thoughts on how to do this (if I should do this)? 回答1: Heroku's docs say to use Tempfile. Well, it says in the doc: There are two directories that are writeable: ./tmp and ./log (under