carrierwaveで複数画像の紐づけを実現したいです。
こちらがカオスになってきて、紐づけを諦めて、別の方法を試すことにして、下記の方法を見つけました。
https://penguin-web.herokuapp.com/blogs/rails/posts/18
カラム追加は実現したのですが、管理画面のactive admin上でアップロードがうまくいきません。。
active adminはgemfileでビューを見つけられません。
すみませんが、ご教示お願いいたします。
###該当するソースコード
Spaceが画像に紐づくモデルとなります。
■ Space.rb
Ruby
1class Space < ApplicationRecord 2 has_many :reviews 3 belongs_to :area 4 has_many :album 5 mount_uploader :image, ImageUploader 6 PICTURE_SIZE = [400, 400] 7 serialize :pictures, Array 8 mount_uploaders :pictures, PictureUploader 9end
ここのmount_uploadersをmount_uploaderとすると、[ファイル選択]が可能になります。mount_uploadersで通すために、active adminのフォームをmultiple :trueにする必要があると思うのですが、active adminの管理画面編集方法がわからず。。。
■ 追加のマイグレーションファイル
Ruby
1class AddPicturesToSpaces < ActiveRecord::Migration[5.0] 2 def change 3 add_column :spaces, :pictures, :text 4 end 5end
■ アップローダー
Ruby
1# encoding: utf-8 2 3class PictureUploader < CarrierWave::Uploader::Base 4 5 include CarrierWave::MiniMagick 6 process :dynamic_resize 7 8 def dynamic_resize 9 resize_to_limit *(model.class::PICTURE_SIZE) 10 end 11 12 storage :file 13 14 def store_dir 15 "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 16 end 17 18 def extension_white_list 19 %w(jpg jpeg gif png) 20 end 21end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/21 06:12
2017/05/21 06:46
2017/05/21 07:08