carrierwave

active_admin and adding multiple images to gallery

余生长醉 提交于 2019-12-06 09:27:35
I'm using active_admin and carrierwave gems. Have two simple models: class Image < ActiveRecord::Base attr_accessible :gallery_id, :file belongs_to :gallery mount_uploader :file, FileUploader end class Gallery < ActiveRecord::Base attr_accessible :description, :title, :file, :images_attributes has_many :images accepts_nested_attributes_for :images, allow_destroy: true mount_uploader :file, FileUploader end Now my active_admin form for Gallery looks like this: form do |f| f.inputs "Gallery" do f.input :title end f.has_many :images do |ff| ff.input :file end f.actions end Now I can upload one

How do I skip a carrierwave store callback when processing versions

痴心易碎 提交于 2019-12-06 08:59:48
问题 I have a callback defined in my video uploader class of carrierwave after :store, :my_method and I have three versions of the files. original , standard , low my_method executes when each version is processed ie, three times, I just need the callback to execute once. 回答1: I know this is a very late response but I was just having the same problem lately so I decided to post how I solved this "problem" since it seems it isn't documented on carrierwave's github page (or I wasn't able to find it

Default URL not loading with Carrierwave in Rails

随声附和 提交于 2019-12-06 08:59:09
问题 I'm having issues setting a default image in my carrierwave uploader. It seems to be appending a weird class to the front of the URL but not rendering the image. See my code below. Helper # encoding: utf-8 class UserpicUploader < CarrierWave::Uploader::Base CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/ # Include RMagick or MiniMagick support: include CarrierWave::RMagick # include CarrierWave::MiniMagick # Include the Sprokets helpers for Rails 3.1+ asset pipeline

How to process only on original image file using CarrierWave?

走远了吗. 提交于 2019-12-06 07:43:46
I use CarrierWave to generate versions (thumbnails with different sizes) and also to add a watermark on each versions. I have currently manage to apply the watermark for each thumbnails but I would like to add it on the original image to. Here is what I tried: def watermark manipulate! do |img| watermark = Magick::Image.read(Rails.root.join('app/assets/images/watermark_512.png')).first img = img.composite(watermark, Magick::CenterGravity, Magick::OverCompositeOp) end end version :original do process :watermark end version :thumb_512 do process :resize_to_fit => [512, 512] process :watermark

How to upload custom S3 metadata with Carrierwave

一世执手 提交于 2019-12-06 07:14:01
问题 I want to add Content-Disposition header to a file I'm uploading with carrierwave (it's not an option to do it afterwards via query param in the URL). Is there something I can add to the AttachmentUploader model that would help me accomplish this, before the file is uploaded? Thanks! 回答1: You can set attributes either globally in your Carrierwave config - CarrierWave.configure do |config| config.fog_attributes = {'Content-Disposition' => ...} end or you can define it on the uploader class

Rails image_tag rotates image

老子叫甜甜 提交于 2019-12-06 06:24:28
问题 I am using Amazon's S3 for image storage with carrierwave and fog configured. The images seem to store correctly however when I have a 'portrait' image (smaller width than height) it is not displaying correctly, but rather rotating the image on its side. Any pointers in the right direction would be much appreciated! uploaders/image_uploader.rb class ImageUploader < CarrierWave::Uploader::Base include CarrierWave::RMagick include Sprockets::Helpers::RailsHelper include Sprockets::Helpers:

Carrierwave Rails 3 S3, save the file size to the database

梦想与她 提交于 2019-12-06 06:16:52
Using Carrierwave with Rails 3.2.6. All fine, except I need to sort a table where some attachments are displayed by file size. I'm using S3 for storage with fog. Let's say I have a Carrierwave showing like this: <%= @project.attachment %> I am able to show the size of the file by using '.size' after the field name: <%= @project.attachment.size %> shows the file size in bytes, but as I need to use an order clause when getting the records from the database, I cannot sort on this. Is there any way to write the file size to a particular column in the database after it has been uploaded so I can

Rails4 : How do I display and edit uploaded file using carrierwave?

谁说我不能喝 提交于 2019-12-06 06:05:25
I can upload a file and save the file name in the database. But the file name doesn't appear when I edit. I'd like to: display the file name and the uploaded image when click "Edit" link in _article.html.erb. display the uploaded image in _article.html.erb. article.rb class Article < ActiveRecord::Base . . has_many :photos, dependent: :destroy accepts_nested_attributes_for :photos . . end photo.rb class Photo < ActiveRecord::Base belongs_to :article mount_uploader :image, ImageUploader validates :image, presence: true #validates :article_id, presence: true end .schema articles CREATE TABLE

Show Rails Carrierwave URL without exposing entire path

折月煮酒 提交于 2019-12-06 04:43:53
I'm making a webapp with paid downloads, and I followed Carrierwave's guide for protecting uploads . Everything is working as expecting save one thing. Here's my current setup: Product File Uploader ... def store_dir "#{Rails.root}/downloads/#{model.product_id}/#{model.id}" end ... Routes get "/downloads/:product_id/:product_file_id/:filename", :controller => "products", action: "download", conditions: {method: :get} ProductsController def download product_file = ProductFile.find(params[:product_file_id]) name = File.basename(product_file.file.file.file) send_file "#{Rails.root}/downloads/#

Conditional versions/process with Carrierwave

怎甘沉沦 提交于 2019-12-06 03:20:54
问题 I have this uploader class class ImageUploader < CarrierWave::Uploader::Base include CarrierWave::RMagick process :resize_to_limit => [300, 300] version :thumb do process :resize_to_limit => [50, 50] end ... Which will process the original file to 300x300 and save a thumb version. I would like to be able to make a small/thumb version only based on a boolean on my model? So I did this if :icon_only? process :resize_to_limit => [50, 50] else process :resize_to_limit => [300, 300] end protected