paperclip

Nested paperclip form with multiple images

对着背影说爱祢 提交于 2019-11-27 07:04:44
问题 I have a one-to-many association between a Banana model and an Image model. In addition, each Banana and Image belong to a User (via a separate association because an Image and its Banana might have different Users). I would like a nested form to create Bananas as well as Images. The kicker is that I don't know how many Images to build (note the multiple attribute). The commented out bit of the form below will create the appropriate amount of Images, but won't complete the associated User

I can't install paperclip

痴心易碎 提交于 2019-11-27 06:52:29
问题 I'm new in rails, I need to install Peperclip (https://github.com/thoughtbot/paperclip) and i can't, I have looked every tutorial I can find and I haven't been able to find where is the bug. I installed the ImageMagick and follow all the instruction of github. When I run: rails generate paperclip club imagen I got this /Users/Moski/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/generators/actions/create_migration.rb:13:in `migration_file_name': protected

How Do I Use Factory Girl To Generate A Paperclip Attachment?

自古美人都是妖i 提交于 2019-11-27 06:03:30
I have model Person that has many Images, where images has a Paperclip attachment field called data, an abbreviated version displayed below: class Person has_many :images ... end class Image has_attached_file :data belongs_to :person ... end Person is required to have at least one Image attached to it. When using FactoryGirl, I have code akin to the following: Factory.define :image do |a| a.data { File.new(File.join(Rails.root, 'features', 'support', 'file.png')) } a.association :person end Factory.define :person do |p| p.first_name 'Keyzer' p.last_name 'Soze' p.after_create do |person| person

Rails Paperclip how to delete attachment?

只谈情不闲聊 提交于 2019-11-27 06:00:36
I am using Paperclip (w/ Amazon s3) on Rails 3. I want to delete an existing attachment without replacing it using an update action. I've only found one example of this here and could not get that to work, it just wouldn't delete and there was nothing in the logs to say why. I wanted to do something like this on the form: <%- unless @page.new_record? || !@page.image? -%> <%= f.check_box :image_delete, :label => 'Delete Image' %> <%- end -%> (page is the name of the model, image is the attribute name which holds the attachment) But how do I detect that checkbox and more importantly, how do I

Allowing User to Download File from S3 Storage

ぃ、小莉子 提交于 2019-11-27 05:29:39
问题 Right now I am using Amazon S3 and Paperclip which is allowing my users to upload an image that is associated with the event they are creating. My ultimate goal is since others can view this event, to be able to click on the image and have it prompt a SAVE TO their computer. As of now, clicking the link will open the image in a browser window. I rather have it ask for them to download instead. All images only saved on S3, not local. Need to hide exposed s3 url as well if possible or

Paperclip renaming files after they're saved

拈花ヽ惹草 提交于 2019-11-27 05:20:00
问题 How do I rename a file after is has been uploaded and saved? My problem is that I need to parse information about the files automatically in order to come up with the file name the file should be saved as with my application, but I can't access the information required to generate the file name till the record for the model has been saved. 回答1: If, for example, your model has attribute image: has_attached_file :image, :styles => { ...... } By default papepclip files are stored in /system/

How can I get url for paperclip image in to_json

邮差的信 提交于 2019-11-27 05:07:29
问题 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 and I want to export the image url so I could use it in javascript. I know I can access the url like this in the view: <%= image_tag model.avatar.url(:medium) %> But How can I do the same in the to_json method. I have some like this: respond_to do

Rails 3 paperclip vs carrierwave vs dragonfly vs attachment_fu [closed]

眉间皱痕 提交于 2019-11-27 03:00:53
I'm working on upgrading a Rails 2.3.11, Ruby 1.9.2 app to Rails 3.0.10, and attachment_fu no longer works. I'm looking at changing to paperclip, carrierwave, or dragonfly for file uploads, or maybe a Rails 3 compatible, maintained version of attachment_fu. Which of these options would be the best to use in terms of performance, how well maintained it is, how easy it is to upgrade from attachment_fu, and maybe is it going to be Rails 3.1 compatible? What are the major strengths and disadvantages of each one? Any insight would be appreciated. I've used both Paperclip and Carrierwave, and if I

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

会有一股神秘感。 提交于 2019-11-26 22:53:15
问题 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. What can I do here? attachment_file_name: "test.md", attachment_content_type: "application/octet-stream", attachment_file_size: 58, attachment_updated_at: "2011-06-22 01:01:40" PS - Seems like all the Paperclip tutorials are about images, not text

File upload with Sinatra

十年热恋 提交于 2019-11-26 22:40:35
问题 I am trying to be able to upload files with Sinatra. I have the code here, but I'm getting the error "method file_hash does not exist" (see /lib/mvc/helpers/helpers.rb). What is going on here? Is there some dependency I'm missing. 回答1: I've had good luck with the example code found on this thread. Including it here in case the link ever disappears: post '/upload' do unless params[:file] && (tmpfile = params[:file][:tempfile]) && (name = params[:file][:filename]) @error = "No file selected"