Permalink
Browse files

Handle missing value_types from preferences

  • Loading branch information...
1 parent 0fa2407 commit cf1bd44ec6706ae2ce420b05c847a50af3f4f18f @BDQ BDQ committed Feb 9, 2012
Showing with 15 additions and 11 deletions.
  1. +15 −11 core/app/models/spree/preference.rb
@@ -9,17 +9,21 @@ class Spree::Preference < ActiveRecord::Base
# The type conversions here should match
# the ones in spree::preferences::preferrable#convert_preference_value
def value
- case self[:value_type].to_sym
- when :string
- self[:value].to_s
- when :password
- self[:value].to_s
- when :decimal
- BigDecimal.new(self[:value].to_s).round(2, BigDecimal::ROUND_HALF_UP)
- when :integer
- self[:value].to_i
- when :boolean
- (self[:value].to_s =~ /^t/i) != nil
+ if self[:value_type].present?
+ case self[:value_type].to_sym
+ when :string
+ self[:value].to_s
+ when :password
+ self[:value].to_s
+ when :decimal
+ BigDecimal.new(self[:value].to_s).round(2, BigDecimal::ROUND_HALF_UP)
+ when :integer
+ self[:value].to_i
+ when :boolean
+ (self[:value].to_s =~ /^t/i) != nil
+ end
+ else
+ self[:value]
end
end

0 comments on commit cf1bd44

Please sign in to comment.