paperclip

Paperclip and Amazon S3 how to do paths?

冷暖自知 提交于 2019-12-03 10:36:15
How do I create paths with paperclip when using Amazon S3? My directory on my bucket is: /image/:id/:filename My model: has_attached_file :image, :storage => :s3, :bucket => 'mybucket', :s3_credentials => { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'] } Try this: has_attached_file :image, :storage => :s3, :bucket => 'mybucket', :path => "/image/:id/:filename", :s3_credentials => { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'] } I wrote a post about it a few months back. I also wrote about how you can add properties from the class, for

Using Paperclip within seeds.rb

假如想象 提交于 2019-12-03 10:16:52
Let's says I have the following entry in my seeds.rb file : Image.create(:id => 52, :asset_file_name => "somefile.jpg", :asset_file_size => 101668, :asset_content_type => "image/jpeg", :product_id => 52) If I seed it, it tries to process the image specified, I get this error : No such file or directory - {file path} etc... My images are backed up, so I don't really need to create them; but I need the record though. I can't comment the paperclip directive in my model; then it works; but I guess there might be another solution. Is there another pattern to follow in order to accomplish it ? Or a

rails paperclip default image with S3

耗尽温柔 提交于 2019-12-03 09:52:10
问题 I'm trying to use the default_url in my application but I store the images using S3. I'm not sure what URL I need to put in there or if I have to create a fake image just to get everything up there. Since my images always render through S3, I don't know if it would work if I just put in some default images in my public folder. It doesn't seem to be working now - I also only have one image in there, and I know it has to resize. I can manually put the resized images in there but I'm still not

undefined method `stringify_keys'

懵懂的女人 提交于 2019-12-03 09:28:40
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 I've seen this error happen before, usually when people attempt to call update_attributes like this: update_attributes(params[:image]) The call should actually be this: update_attributes(:image => params[

Multiple Paperclip default_urls

时光怂恿深爱的人放手 提交于 2019-12-03 09:08:08
I am using Paperclip to upload an image to my Project model and I want to have an array of default images (not depending on the style, but different images) is that posible? To pass an array instead of just one URL to the :default_url option? Thank you, Nicolás Hock Isaza So close: If you want the images to change randomly, and not just on first load of the model: :default_url => lambda { "path/to/images/#{rand(5)}.jpg" } Putting rand(5) in the default_url proc will assign a random image every time a new model object is created. If you want the images to be randomly assigned and that each

Save a Prawn PDF as a Paperclip attachment?

无人久伴 提交于 2019-12-03 08:32:20
问题 I'm using Prawn and Prawnto to display a PDF-based reports to the user, but in some circumstances, I'd also like to save the PDF as an attachment to one of my models. I'm using Paperclip for all of my attachments. Does anyone have any suggestions on how to do this? Thanks! 回答1: When using prawnto you will need to eval the variables in the .pdf.prawn template. Second step is to mimic a real file for paperclip. Generating the PDF: #find the prawwnto template you want template = File.read("#

Rails 4 Paperclip FactoryGirl file uploading

元气小坏坏 提交于 2019-12-03 08:31:24
I have a FactoryGirl :product factory that uses fixture_file_upload to set image , which is a Paperclip attachment. image { fixture_file_upload "#{Rails.root}/spec/fixtures/images/product.png", 'image/png' } fixture_file_upload works fine, but every time a test creates a new Product using the factory, Paperclip creates a new file in publicproducts/<id>/original.png . This is the issue. . Filling a the folder publicproducts on each test run is not acceptable. The first workaround I can think of is the solution mentioned in https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-Cleanup

Save files using paperclip via API

微笑、不失礼 提交于 2019-12-03 07:48:49
I'm using paperclip to manage uploads, backed onto S3 via Fog. It works well. I'm trying to take attachments out of emails and save them via paperclip (using the same model etc). Email are parsed by an external service and POSTed to my app, including the attachments. I'm receiving the file itself fine, but I can't work out how to save it using paperclip. The post gives me an object of type ActionDispatch::Http::UploadedFile . I took a look at the below, but this involves creating a new File object. I'm not sure this is what I want... How should I do it? Saving files using Paperclip without

Paperclip :style depending on model (has_many polymorphic images)

匆匆过客 提交于 2019-12-03 07:35:09
问题 I have set up my models to use a polymorphic Image model. This is working fine, however I am wondering if it is possible to change the :styles setting for each model. Found some examples using STI (Model < Image) However this is not an option for me, because I am using a has_many relation. Art has_many :images, :as => :imageable Image belongs_to :imageable, :polymorphic => true has_attached_file :file, :styles => { :thumb => "150x150>", :normal => "492x600>"} #Change this setting depending on

Generate Thumbnail From pdf in rails paperclip

混江龙づ霸主 提交于 2019-12-03 06:38:36
How can I generate the first page of a pdf as a thumbnail in paperclip? I tried a lot but it's not working has_attached_file :book_url, :styles => { :thumb => "100x100#", :small => "150x150>", :medium => "200x200" } This is giving the name of the pdf as a link but it's not giving the first page of the pdf <%= link_to 'My PDF', @book.book_url.url %> Tadas' answer is right, but for those who need more context, you can do something like this: The model below only creates thumbnails for certain kinds of files (e.g. it doesn't make thumbnails of audio files), but does make thumbnails for pdfs,