EzDevInfo.com

paperclip.js

reactive DOM template engine built for speed, and extensibility Paperclip.js - fast, reactive template engine for the DOM

How to set a file upload programmatically using Paperclip

I have a rake task to seed an application with random data using the faker gem. However, we also have images (like logos) that we want uploaded in this rake task.

We already have Paperclip set up, but don't have a way to upload them programmatically in a rake task. Any ideas?


Source: (StackOverflow)

unit test in rails - model with paperclip

I'm trying to write a test for a model with a picture, using paperclip. I'm using the test framework default, no shoulda or rspec. In this context, how should I test it? Should I really upload a file? How should I add a file to the fixture?


Source: (StackOverflow)

Advertisements

heroku paperclip weird error Paperclip::Errors::MissingRequiredValidatorError

I've deployed a rails app to heroku, it was working just fine until I changed domains, locally it works fine and now I've started getting the following error: Paperclip::Errors::MissingRequiredValidatorError.

the s3 env variables are set on heroku and I can't find why this error occurs, help is appreciated.

EDIT: for future reference, it had nothing to do with heroku, once re-bundling, it'll throw the same error locally, as the answer suggest.


Source: (StackOverflow)

Default_url in Paperclip Broke with Asset Pipeline Upgrade

I'm using Paperclip and have a default_url option like this for one of my attachments:

:default_url => '/images/missing_:style.png'

The asset pipeline obviously doesn't like this since the directories moved. What's the best way to handle this? I have two styles for this picture (:mini and :thumb).


Source: (StackOverflow)

Save image from URL by paperclip

Please suggest me a way to save an image from an URL by Paperclip.


Source: (StackOverflow)

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

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.


Source: (StackOverflow)

Saving the images Dimensions (width and height) in Paperclip?

Any Paperclip wizards out there know if you can when using Paperclip to save an image, also save the image dimensions (width and height) in 2 extra fields? How do you get such data during the Paperclip upload process?


Source: (StackOverflow)

undefined method `stringify_keys'

When I try to upload image using Paperclip gem I got this error:

NoMethodError (undefined method `stringify_keys' for <ActionDispatch::Http::UploadedFile:0x000000025387f0>)

class MenuItem < ActiveRecord::Base
 has_one :image


end

class Image < ActiveRecord::Base
 belongs_to :menu_item
 has_attached_file :image, :styles => {
            :large => "640x480",
            :medium => "300x300", 
            :thumb => "100x100" 
           }
end

Source: (StackOverflow)

Saving files using Paperclip without upload

I had a quick question. Is it possible to save a file without actually uploading it through a form?

For example, lets say i'm looking at attachments from emails, and i want to save them using paperclip. How do i do this? Do i manually have to call a save_file(or something similar) somewhere?

Any help would be much appreciated!


Source: (StackOverflow)

Simple cropping with Paperclip

I would like to crop images on upload using Paperclip to get square thumbs from the center of the original picture. I find out a method in documentation that seems to do exactly what I want:

transformation_to(dst, crop = false)

The problem is that I can't figure out where to use this method. It would be great to simply pass something as a parameter here:

  has_attached_file :picture, 
                    :styles => { :medium => "600x600>", :thumb => "something here" }

Source: (StackOverflow)

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

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.assets = [Factory.build(:image, :person => person)]
  end
  # p.images {|images| [images.association(:image)]}
end

(N.B. I have also tried the code commented out above was also tried) Most of the time when I run cucumber features, I get an error akin to the following:

No such file or directory - /tmp/stream,9887,0.png (Errno::ENOENT)

...

Sometimes the tests run successfully.

Can anyone tell me what the problem is I am having here or how they use FactoryGirl and Paperclip together to achieve something like what I am trying to achieve?

I am using Rails 3.


Source: (StackOverflow)

Paperclip::Errors::MissingRequiredValidatorError with Rails 4

I'm getting this error when I try to upload using paperclip with my rails blogging app. Not sure what it is referring to when it says "MissingRequiredValidatorError" I thought that by updating post_params and giving it :image it would be fine, as both create and update use post_params

Paperclip::Errors::MissingRequiredValidatorError in PostsController#create
Paperclip::Errors::MissingRequiredValidatorError

Extracted source (around line #30):

def create
  @post = Post.new(post_params)

This is my posts_controller.rb

def update
  @post = Post.find(params[:id])

  if @post.update(post_params)
    redirect_to action: :show, id: @post.id
  else
    render 'edit'
  end
end

def new
  @post = Post.new
end

def create
  @post = Post.new(post_params)

  if @post.save
    redirect_to action: :show, id: @post.id
  else
    render 'new'
  end
end
#...

private

def post_params
  params.require(:post).permit(:title, :text, :image)
end    

and this is my posts helper

module PostsHelper
  def post_params
    params.require(:post).permit(:title, :body, :tag_list, :image)
  end
end

Please let me know if I can supplement extra material to help you help me.


Source: (StackOverflow)

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

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 PostsController#index or perhaps a previously attempt at installing the gem instead of the plugin, in which case I have read I should be able to remedy through the /config/environments.rb file somehow.

I didn't think that previous gem installation would matter as I did it in an old version of the site that I trashed before installing the plugin. In the current version of the site I show that the table has been updated with the Paperclip columns after migration. Here is my code:

PostsConroller#show:

  def show
    @post = Post.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @post }
    end
  end

Post model:

class Post < ActiveRecord::Base

  has_attached_file :photo
  validates_presence_of :body, :title
  has_many :comments, :dependent => :destroy
  has_many :tags, :dependent => :destroy
  has_many :votes, :dependent => :destroy
  belongs_to :user
  after_create :self_vote
      def self_vote
       # I am assuming you have a user_id field in `posts` and `votes` table.
       self.votes.create(:user => self.user)
      end

  cattr_reader :per_page 
    @@per_page = 10

end

/views/posts/new.html.erb:

<h1>New post</h1>
<%= link_to 'Back', posts_path %>
<% form_for(@post, :html => { :multipart => true}) do |f| %>
  <%= f.error_messages %>

  <p>
    <%= f.label :title %><br />
    <%= f.text_field :title %>
  </p>
  <p>
    <%= f.label :body %><br />
    <%= f.text_area :body %>
  </p>
  <p>
    <%= f.file_field :photo %>
  </p>

  <p>
    <%= f.submit 'Create' %>
  </p>
<% end %>

Source: (StackOverflow)

Paperclip exception : Paperclip::AdapterRegistry::NoHandlerError

Using Paperclip 3.0.1 in rails 3.2.2 I got this error:

**Paperclip::AdapterRegistry::NoHandlerError** 
(No handler found for "2009-11-29-133527.jpg"):

In my model I have:

class Product < ActiveRecord::Base
    ...
    has_many :assets 
    accepts_nested_attributes_for :assets
 end

 class Asset < ActiveRecord::Base
     belongs_to :product
     has_attached_file :image,
               :path => ":rails_root/public/system/:attachment/:id/:style/:filename",
               :url => "/system/:attachment/:id/:style/:filename", 
               :styles => { :medium => "300x300>", :thumb => "100x100>" }
  end

The exception is raised at:

def create
     **@product = Product.new params[:product]**
     ...
end

with params:

{...,
 "product"=>{"title"=>"wibble1", 
             **"assets_attributes"=>{"0"=>{"image"=>"2009-11-29-133527.jpg"}
                                  },** 
             "description"=>"Who is wibble...", 
             "price"=>"23.45"
            }, 
             "commit"=>"Create Product", 
             ...}

Anyone know what's going on?


Source: (StackOverflow)

Resize an image with Paperclip

The Paperclip plugin for Rails has a resize option that keeps the image in proportion. According to Ryan Bates' Paperclip Railscast, to make sure that option is on, you have to add a greater-than sign in the end of the size for the style you're looking to resize, as such:

:styles => { :small => "160x160>" }

I'm looking for Paperclip to resize my image to an exact size, even if that means it being out of proportion, so I figured that removing the greater-than sign would do the trick, as such:

:styles => { :small => "160x160" }

Well, turns out nothing happens. So the greater-than sign is redundant in the first place. I'm still left with the following question, though:

How would I force the image into a set size, ignoring proportions?

Thanks!


Source: (StackOverflow)