piggybak_variants 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,10 @@
1
1
  :ruby
2
2
  column_type_dom_id = form.dom_id(field).sub(field.method_name.to_s, "")
3
- attr = column_type_dom_id.gsub(/[a-z]+_variants_attributes/, '').gsub(/^_/, '[').gsub(/_$/, ']')
3
+ attr = column_type_dom_id.gsub(/[a-z_]+_variants_attributes/, '').gsub(/^_/, '[').gsub(/_$/, ']')
4
4
 
5
5
  - options_for_klass(@object.class).each do |option|
6
6
  %h5= option.name
7
+ = hidden_field_tag "#{@object.class.to_s.downcase}[variants_attributes]#{attr}[option_value_ids][]", nil
7
8
  - option.option_values.each do |option_value|
8
9
  %p
9
10
  = check_box_tag "#{@object.class.to_s.downcase}[variants_attributes]#{attr}[option_value_ids][]", option_value.id, form.object.option_values.include?(option_value), :style => "margin:-2px 5px 0px 0px;"
@@ -8,7 +8,8 @@ module Piggybak
8
8
 
9
9
  accepts_nested_attributes_for :variants, :allow_destroy => true
10
10
  attr_accessible :variants_attributes #, :allow_destroy => true
11
-
11
+ validates_associated_bubbling :variants
12
+
12
13
  ::PiggybakVariants::OptionConfiguration::VARIANT_CLASSES << self.to_s
13
14
  end
14
15
  end
@@ -0,0 +1,21 @@
1
+ module ActiveRecord
2
+ module Validations
3
+ class AssociatedBubblingValidator < ActiveModel::EachValidator
4
+ def validate_each(record, attribute, value)
5
+ (value.is_a?(Array) ? value : [value]).each do |v|
6
+ unless v.valid?
7
+ v.errors.full_messages.each do |msg|
8
+ record.errors.add(attribute, msg, options.merge(:value => value))
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ module ClassMethods
16
+ def validates_associated_bubbling(*attr_names)
17
+ validates_with AssociatedBubblingValidator, _merge_attributes(attr_names)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module PiggybakVariants
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "piggybak_variants/engine"
2
+ require 'associated_bubbling_validator'
2
3
  require "acts_as_sellable_with_variants"
3
4
 
4
5
  module PiggybakVariants
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piggybak_variants
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-16 00:00:00.000000000 Z
12
+ date: 2012-12-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -54,6 +54,7 @@ files:
54
54
  - lib/piggybak_variants/engine.rb
55
55
  - lib/piggybak_variants/version.rb
56
56
  - lib/acts_as_sellable_with_variants.rb
57
+ - lib/associated_bubbling_validator.rb
57
58
  - MIT-LICENSE
58
59
  - Rakefile
59
60
  - README.md
@@ -102,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
103
  version: '0'
103
104
  segments:
104
105
  - 0
105
- hash: -1851012769668086363
106
+ hash: 2027483613391823744
106
107
  required_rubygems_version: !ruby/object:Gem::Requirement
107
108
  none: false
108
109
  requirements:
@@ -111,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  version: '0'
112
113
  segments:
113
114
  - 0
114
- hash: -1851012769668086363
115
+ hash: 2027483613391823744
115
116
  requirements: []
116
117
  rubyforge_project:
117
118
  rubygems_version: 1.8.23