Default_url in Paperclip Broke with Asset Pipeline Upgrade
:default_url => ActionController::Base.helpers.asset_path(‘missing_:style.png’) Then put the default images in app/assets/images/
:default_url => ActionController::Base.helpers.asset_path(‘missing_:style.png’) Then put the default images in app/assets/images/
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
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
Here is my code that worked well to upload multiple file using paperclip: We can achieve using nested attributes or using normal easy method. The following code shows normal method: User.rb has_many :images, :dependent => :destroy Image.rb has_attached_file :avatar, :styles => { :medium => “300×300>” } belongs_to :user users/views/new.html.erb <%= form_for @user, :html => { … Read more
This Error is raised because you aren’t giving Paperclip a correct class. It’s a just a String. You should receive something like this in params “asset”=> {“image”=> #<ActionDispatch::Http::UploadedFile:0x000000056679e8 @content_type=”image/jpg”, @headers= “Content-Disposition: form-data; name=\”asset[image]\”; filename=\”2009-11-29-133527.jpg\”\r\nContent-Type: image/jpg\r\n”, @original_filename=””2009-11-29-133527.jpg””, @tempfile=#<File:/tmp/RackMultipart20120619-1043-yvc9ox>>} And you should have something like this in yout View (in HAML, very simplified): = form_for @product, html: … Read more
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