Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Carrierwave mounted to Rails 4 PostgreSQL array attribute

Since Rails >= 4.0 adds support for PostgreSQL array data types I was wondering if anyone already played with carrierwave attachments mounted to array attributes instead of join tables when a model should have multiple attachments.

What I got in mind is something like

class AddPicturesToUser < ActiveRecord::Migration
  def change
    add_column :users, :pictures, :text, array: true
  end
end

class User < ActiveRecord::Base
  mount_uploader :pictures, PictureUploader, array: true
end
like image 206
pex Avatar asked Jun 21 '14 11:06

pex


1 Answers

Check https://github.com/carrierwaveuploader/carrierwave/issues/1548

switch to the github version of the carrierwave gem

gem 'carrierwave', github: 'carrierwaveuploader/carrierwave'

Use mount_uploaders instead of mount_uploader in your class as described in the carrierwave wiki.

mount_uploaders :pictures, PictureUploader

remove the, array:true at the end of the mount_uploader.

like image 109
Cris Avatar answered Sep 28 '22 19:09

Cris