-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We can create an ImageGallery with its images, so we then link it with the fields See #869
- Loading branch information
1 parent
90b9edb
commit fd87425
Showing
7 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class ImageGallery < ActiveRecord::Base | ||
belongs_to :site | ||
belongs_to :field | ||
mount_uploaders :images, ImageGalleryUploader | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# encoding: utf-8 | ||
class ImageGalleryUploader < CarrierWave::Uploader::Base | ||
storage :file | ||
|
||
# Override the directory where uploaded files will be stored. | ||
# This is a sensible default for uploaders that are meant to be mounted: | ||
def store_dir | ||
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" | ||
end | ||
|
||
def full_filename(filename) | ||
"#{SecureRandom.uuid}-#{filename}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreateImageGalleries < ActiveRecord::Migration | ||
def change | ||
create_table :image_galleries do |t| | ||
t.integer :site_id | ||
t.integer :field_id | ||
t.text :images | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'spec_helper' | ||
|
||
describe "Image Gallery" do | ||
it "uploads multiple logos" do | ||
file = File.open('spec/fixtures/tracking_food.jpg') | ||
file2 = File.open('spec/fixtures/tracking_food.jpg') | ||
instance = ImageGallery.new | ||
instance.images = [file, file2] | ||
instance.save! | ||
instance.images.count.should eq(2) | ||
instance.images.each do |image| | ||
get image.url | ||
response.should be_success | ||
end | ||
end | ||
|
||
end |