Skip to content
This repository has been archived by the owner on Jul 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #18 from killinit/master
Browse files Browse the repository at this point in the history
Add Image to option values
  • Loading branch information
Steph Skardal committed Feb 9, 2015
2 parents 4fc6f9d + 0fc910a commit 1cf3b0e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/models/piggybak_variants/option_value.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module PiggybakVariants
class OptionValue < ActiveRecord::Base
has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/

has_and_belongs_to_many :variants
belongs_to :option, :inverse_of => :option_values

Expand Down
1 change: 1 addition & 0 deletions app/views/rails_admin/main/_option_values.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
- option.option_values.each do |option_value|
%p
= check_box_tag "#{@object.class.to_s.underscore}[variants_attributes]#{attr}[option_value_ids][]", option_value.id, form.object.option_values.include?(option_value), :style => "margin:-2px 5px 0px 0px;"
= image_tag option_value.image.url(:thumb)
%span= option_value.name
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddImageToPiggybakVariantsOptionValues < ActiveRecord::Migration
def self.up
add_attachment :piggybak_variants_option_values, :image
end

def self.down
remove_attachment :piggybak_variants_option_values, :image
end
end
1 change: 1 addition & 0 deletions lib/piggybak_variants/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Engine < ::Rails::Engine
object_label_method :admin_label
edit do
field :name
field :image, :paperclip
field :position
end
end
Expand Down
2 changes: 2 additions & 0 deletions piggybak_variants.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ Gem::Specification.new do |s|

s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"]
s.test_files = Dir["test/**/*"]

s.add_dependency 'paperclip'
end

0 comments on commit 1cf3b0e

Please sign in to comment.