paperclip

rails 3 polymorphic association with paperclip and multiple models

≯℡__Kan透↙ 提交于 2019-11-29 09:31:18
问题 I want to make polymorphic associations with paperclip, and allow my user to have one avatar and multiple images. Attachment model: class Attachment < ActiveRecord::Base belongs_to :attachable, :polymorphic => true end class Avatar < Attachment has_attached_file :image, :styles => { :thumb => "150x150>", :view => "260x180>" }, end class Image < Attachment has_attached_file :image, :styles => { :thumb => "150x150>", :view => "260x180>" }, end User Model: has_one :avatar, :as => :attachable,

Paperclip Error: model missing required attr_accessor for 'avatar_file_name'

我们两清 提交于 2019-11-29 09:19:57
I then want to use Paperclip to have photos for each Listing. I added the appropriate code to the listings show.html.erb, the listing.rb model, the listings_controller.rb and the _form.html.erb partial. When I try uploading an image for the Listing I get this error: Paperclip::Error in ListingsController#update Listing model missing required attr_accessor for 'avatar_file_name' Line 44 of listings_controller: def update respond_to do |format| if @listing.update(listing_params) format.html { redirect_to @listing, notice: 'Listing was successfully updated.' } format.json { head :no_content }

Trouble resizing the default image with Paperclip

痴心易碎 提交于 2019-11-29 08:38:40
问题 I want to be able to resize the default profile image I use with Paperclip. This is the code in my model: has_attached_file :photo, :styles => { :tiny => "25x25#", :thumbnail => "100x100#", :small => "150x150>", :medium => "300x300>" }, :default_url => "/images/default.png" However, the default image doesn't get resized like the user submitted images do. How can I do this? 回答1: The solution I've been using is to specify the style for the default image: has_attached_file :photo, :styles => {

Exception when trying to upload file from Flex to Rails (using paperclip)

岁酱吖の 提交于 2019-11-29 08:16:37
I'm trying to upload a Dynamically generated file from Flex (PNG image) to Ruby on Rails Server back end using the following code (from Flex on Rails book): public function save():void { var bitmapData:BitmapData = new BitmapData(width, height); bitmapData.draw(this); var ba:ByteArray = (new PNGEncoder()).encode(bitmapData); var fileRef:FileReference = new FileReference(); //TODO: Remove HardCoding of URL here var request : URLRequest = new URLRequest("http://localhost:3000/doodles"); request.method = URLRequestMethod.POST; var boundary : String = "----------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7";

Failing to install Nokogiri gem

旧巷老猫 提交于 2019-11-29 06:21:22
问题 I'm working on a rails app that allows for image attachments to each use account. I'm using paperclip and amazon web services: gem 'paperclip' gem 'aws-sdk' When I run bundle install, I get this message: extconf failed, exit code 1 Gem files will remain installed in /usr/local/rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.5 for inspection. Results logged to /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-darwin-13/2.1.0-static/nokogiri-1.6.5/gem_make.out An error occurred while installing nokogiri

Preventing Paperclip from deleting/overwriting attachments on update

非 Y 不嫁゛ 提交于 2019-11-29 06:07:59
问题 I'm having a hard time figuring out how to prevent Paperclip from deleting the old version of an attachment (image). I have a model, Site, which has an attachment, logo. I would like to keep the old logos around since I will be keeping track of changes to the model and would like to view the history of logos. I'm keeping track of the changes in another model, which has a reference to file paths. My problem is that when updating a site with a new logo, Paperclip will flush the old logo first.

How to copy a file using Paperclip

孤者浪人 提交于 2019-11-29 05:34:32
Does anyone know of a way to copy files with Paperclip using S3 for storage? Before I try to write my own, I just wanted to make sure there wasn't already a way to do this. Thanks After some more messing around with paperclip, I figured it out. It's ridiculously simple to copy files! # Stupid example method that just copies a user's profile pic to another user. def copy_profile_picture(user_1, user_2) user_2.picture = user_1.picture user_2.save # Copied the picture and we're done! end This also works great with amazon s3. Sweet 来源: https://stackoverflow.com/questions/2739839/how-to-copy-a-file

Why do I get an "undefined method for `has_attached_file` when installing PaperClip?

左心房为你撑大大i 提交于 2019-11-29 04:30:53
问题 I just installed the plugin for Paperclip and I am getting the following error message but I am not sure why: NoMethodError (undefined method `has_attached_file' for #<Class:0x10338acd0>): /Users/bgadoci/.gem/ruby/1.8/gems/will_paginate-2.3.12/lib/will_paginate/finder.rb:170:in `method_missing' app/models/post.rb:2 app/controllers/posts_controller.rb:50:in `show' It is referencing the will_paginate gem. From what I can find, it seems that either there is something wrong with my

Paperclip in Rails 4 - Strong Parameters Forbidden Attributes Error

旧街凉风 提交于 2019-11-29 04:04:19
Having a problem with a Paperclip upload in Rails 4 - failing on ForbiddenAttributesError (strong parameters validation). Have the latest paperclip gem and latest rails 4 gems. I have a model "Image" with an attached file "upload" in the model: has_attached_file :upload, :styles => { :review => ["1000x1200>", :png], :thumb => ["100x100>", :png]}, :default_url => "/images/:style/missing.png" The image model was created with a scaffold, and I added paperclip migrations. The form partial was updated to use f.file_field :upload the form generates what appears to be a typical set of paperclip

Dynamic use of :default_url in Paperclip

送分小仙女□ 提交于 2019-11-29 03:53:31
I'm trying to configure Paperclip to provide different missing images based on the instance's category attribute. Every category of the object has its own missing image. This is my first take: EDIT to add full models: class Service < ActiveRecord::Base attr_accessible :logo, :logo_file_name, :logo_content_type, :logo_file_size, :logo_updated_at belongs_to :category, :counter_cache => true has_attached_file :logo, :path => "/:id-:style-:filename", :url => ":s3_eu_url", :default_url => "/logos/:style/#{self.category.name]}.png", :styles => { :large => "600x400>", :medium => "300x200>", :small =>