Resize existing images to new style in paperclip & RMagick

You want the reprocess! method of Paperclip::Attachment. See the docs. class User < ActiveRecord::Base has_attached_file :avatar, :styles => { :medium => “300×300>”, :thumb => “100×100>” } end # Console… >> User.find_each { |u| u.avatar.reprocess! } Also, according to the comments before the reprocess! method, there’s a paperclip:refresh Rake task, which might be easier.

How to set a file upload programmatically using Paperclip

What do you mean by programmatically? You can set up a method that will take a file path along the lines of my_model_instance = MyModel.new file = File.open(file_path) my_model_instance.attachment = file file.close my_model_instance.save! #attachment comes from our Paperclip declaration in our model. In this case, our model looks like class MyModel < ActiveRecord::Base has_attached_file :attachment … Read more

Rails Paperclip how to delete attachment?

First off, when you create a check_box in a form_for (which it looks like you are), then the form should by default send :image_delete as “1” if checked and “0” if unchecked. The method declaration looks like this: def check_box(method, options = {}, checked_value = “1”, unchecked_value = “0”) Which shows that you can assign … Read more

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

You can use fixture_file_upload include ActionDispatch::TestProcess in your test helper, here is an example factory: include ActionDispatch::TestProcess FactoryBot.define do factory :user do avatar { fixture_file_upload(Rails.root.join(‘spec’, ‘photos’, ‘test.png’), ‘image/png’) } end end In the above example, spec/photos/test.png needs to exist in your application’s root directory before running your tests. Note, that FactoryBot is a new name … Read more

Save image from URL by paperclip

In Paperclip 3.1.4 it’s become even simpler. def picture_from_url(url) self.picture = URI.parse(url) end This is slightly better than open(url). Because with open(url) you’re going to get “stringio.txt” as the filename. With the above you’re going to get a proper name of the file based on the URL. i.e. self.picture = URI.parse(“http://something.com/blah/avatar.png”) self.picture_file_name # => “avatar.png” … Read more

Paperclip::Errors::MissingRequiredValidatorError with Rails 4

Starting with Paperclip version 4.0, all attachments are required to include a content_type validation, a file_name validation, or to explicitly state that they’re not going to have either. Paperclip raises Paperclip::Errors::MissingRequiredValidatorError error if you do not do any of this. In your case, you can add any of the following line to your Post model, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)