paperclip

Make a field optional in rails

China☆狼群 提交于 2019-12-01 23:45:25
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 must be between 0 and 1048576 bytes. * Avatar content type is not included in the list is there anyway

Undefined method `has_attached_file' with paperclip 2.3.8 gem for Rails 2 using Ruby 1.8.7

狂风中的少年 提交于 2019-12-01 23:07:36
I am trying to use the paperclip plugin in my rails app to upload images for posts. I am using Rails 2.0.2 and ruby 1.8.7 on Ubuntu 10.04 os for project specific purposes. I am referring to the following tutorials for this :- http://railscasts.com/episodes/134-paperclip?view=comments http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails.html I did a git clone on the paperclip plugin via:- https://github.com/thoughtbot/paperclip , but the command like ruby script/generate paperclip group_post photo didn't generate a migration for it. I then created a migration for the same through

Paperclip attachment file size

北慕城南 提交于 2019-12-01 18:14:54
How do I fetch the file size of each style of a paperclip attachment? @user.attachment_file_size doesn't seem to work @user.attachment(:style).size gives a number not related to the actual file size I didn't find either how to get the file size for a given style , other than the original one. As seen in the paperclip source code , @user.attachment.size returns the size of the file as originally assigned. There is no way to get it for a specific style... A solution would be: open(@user.attachment(:style)).size But not efficient at all. To do it well, you should probably add some "custom size"

How can I reduce the quality of an uploading image using Paperclip?

荒凉一梦 提交于 2019-12-01 18:05:00
I am running Ruby on Rails 3 and I would like to reduce the quality of an uploading image using the Paperclip plugin/gem. How can I do that? At this time in my model file I have: has_attached_file :avatar, :styles => { :thumb => ["50x50#", :jpg], :medium => ["250x250#", :jpg], :original => ["600x600#", :jpg] } that will convert images in to the .jpg format and will set dimensions. Try using convert_options. has_attached_file :avatar, :styles => { :thumb => '50x50#' }, :convert_options => { :thumb => '-quality 80' } Peter Brown From the paperclip wiki , there's an option for quality: class User

Paperclip attachment file size

£可爱£侵袭症+ 提交于 2019-12-01 17:24:20
问题 How do I fetch the file size of each style of a paperclip attachment? @user.attachment_file_size doesn't seem to work @user.attachment(:style).size gives a number not related to the actual file size 回答1: I didn't find either how to get the file size for a given style , other than the original one. As seen in the paperclip source code, @user.attachment.size returns the size of the file as originally assigned. There is no way to get it for a specific style... A solution would be: open(@user

Ruby on rails - paperclip not saving to database

夙愿已清 提交于 2019-12-01 17:22:20
I'm trying to make a create product page in rails. This includes adding multiple images. I have one model for products one for photos and for users. I'm using the paperclip gem for photo upload. But I have 2 problems. My file input is not allowing me to select multiple images When I view a product no pictures show because pictures are not being saved to database P.S. I use HAML and I dont have a photo controller. Products controller class ProductsController < ApplicationController before_filter :current_user, only: [:create, :destory] before_filter :correct_user, only: :destory def new

Paperclip process images only

时间秒杀一切 提交于 2019-12-01 15:24:47
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 here is uploading the file by FTP, and later on create a new record by code with a File.new([:path]) in

Paperclip not displaying the error message

倖福魔咒の 提交于 2019-12-01 14:42:42
I am using rails 3.2.6. I have added this in my models file: has_one :avatar, :as => :imageable, :dependent => :destroy validates_presence_of :avatar, :message => "can't be empty" But I am not getting any error message if the field is left blank.I am only getting Please review the problems below: at the top of my page. Can anyone suggest anything? has_one :avatar, :as => :imageable, :dependent => :destroy has_many :attachments, :as => :attachable, :dependent => :destroy accepts_nested_attributes_for :avatar, :reject_if => :all_blank Actually how to give error message in nested attributes? 来源:

Access Denied when uploading files to Amazon using Paperclip and IAM policies

我怕爱的太早我们不能终老 提交于 2019-12-01 14:38:32
问题 I am unable to get an upload working with Paperclip using an S3 IAM policy. I'm even having issues with direct jQuery uploads (no Paperclip). My scenario is as follows, I have an application that will have many sites. Each site will have it's own bucket and should only be able to access their own bucket, nobody else's. The IAM Example Policies documentation explains exactly what I want to do under "Example: Allow each IAM user access to a folder in a bucket". I have an IAM group set up for

Rails 4: Heroku + Paperclip + s3 not working in production

ぐ巨炮叔叔 提交于 2019-12-01 13:36:07
问题 so im following this tutorial: https://devcenter.heroku.com/articles/paperclip-s3 I manage to deploy it to Heroku and App is working in the development. The app is running in Heroku but when i try to upload photo. it gives me this page We're sorry, but something went wrong. I try to debug it by going to console and typing heroku logs it gives me the following error: heroku[router]: at=info method=POST path="/friends" host=s3friends.herokuapp.com request_id=4173ed9e-ed69-492c-b1b9-d98227ca678c