Created
March 31, 2012 14:34
-
-
Save anonymous/2265580 to your computer and use it in GitHub Desktop.
Issue with 0:Fixnum
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
rake aborted! | |
undefined method `to_d' for 0:Fixnum | |
C:/teststore/app/models/product.rb:55:in `shipping_cost=' | |
C:/teststore/app/models/product.rb:126:in `default_to_zero_if_necessary' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/callbacks.rb:396:in `_run_validation_callbacks' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/callbacks.rb:81:in `run_callbacks' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/validations/callbacks.rb:53:in `run_validations!' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activemodel-3.1.0/lib/active_model/validations.rb:179:in `valid?' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/validations.rb:69:in `valid?' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/validations.rb:77:in `perform_validations' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/validations.rb:50:in `save' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/attribute_methods/dirty.rb:22:in `save' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/transactions.rb:241:in `block (2 levels) in save' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/transactions.rb:208:in `transaction' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/transactions.rb:293:in `with_transaction_returning_status' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/transactions.rb:241:in `block in save' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/transactions.rb:252:in `rollback_active_record_state!' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/transactions.rb:240:in `save' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/associations/has_many_association.rb:16:in `insert_record' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/associations/collection_association.rb:421:in `block (2 levels) in create_record' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/associations/collection_association.rb:333:in `add_to_target' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/associations/collection_association.rb:419:in `block in create_record' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/associations/collection_association.rb:143:in `block in transaction' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/transactions.rb:208:in `transaction' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/associations/collection_association.rb:142:in `transaction' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/associations/collection_association.rb:418:in `create_record' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/associations/collection_association.rb:416:in `block in create_record' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/associations/collection_association.rb:416:in `collect' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/associations/collection_association.rb:416:in `create_record' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/associations/collection_association.rb:107:in `create' | |
c:in `create' | |
C:/teststore/db/seeds.rb:35:in `<top (required)>' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `block in load' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `block in load_dependency' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:234:in `load' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/engine.rb:487:in `load_seed' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:299:in `block (2 levels) in <top (required)>' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `call' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `each' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `execute' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:597:in `block in invoke_with_call_chain' | |
c:/Ruby192/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 levels) in top_level' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `each' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top_level' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:1998:in `run' | |
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.8.7/bin/rake:31:in `<top (required)>' | |
c:/Ruby192/bin/rake:19:in `load' | |
c:/Ruby192/bin/rake:19:in `<main>' |
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
class Product < ActiveRecord::Base | |
attr_accessible :cost, :purchase_date, :link, :store_id, :tax_rate, :shipping_cost, :cost_per_unit, :unit, :unit_amount | |
belongs_to :user | |
belongs_to :store | |
validates_presence_of :store | |
after_save { |up| up.destroy if up.store.blank?} | |
before_validation :default_to_zero_if_necessary, :on => :create | |
UNITS = ["seconds", "days", "hours", "weeks", 'years', "feet", 'inches', 'pounds', "kilograms", 'grams', | |
'metres', 'centimetres', 'milimetres', 'gallons', 'quarts', 'cups', 'pints', "cubic feet", "cubic inches", "cubic metres", "fluid ounces", 'pieces', "parts"] | |
validates_inclusion_of :unit, :in => UNITS, :allow_blank => true | |
def shipping_cost=(num) | |
num.gsub!(',','') if num.is_a?(String) | |
self[:shipping_cost] = num.to_d | |
end | |
def cost=(num) | |
num.gsub!(',','') if num.is_a?(String) | |
self[:cost] = num.to_d | |
end | |
def tax_rate=(num) | |
num.gsub!(',','') if num.is_a?(String) | |
self[:tax_rate] = num.to_d | |
end | |
def cost_per_unit=(num) | |
num.gsub!(',','') if num.is_a?(String) | |
self[:cost_per_unit] = num.to_d | |
end | |
def unit_amount=(num) | |
num.gsub!(',','') if num.is_a?(String) | |
self[:unit_amount] = num.to_d | |
end | |
private | |
def default_to_zero_if_necessary | |
self.tax_rate = 0 if self.tax_rate.blank? | |
self.shipping_cost = 0 if self.shipping_cost.blank? | |
self.cost = 0 if self.cost.blank? | |
self.cost_per_unit = 0 if self.cost_per_unit.blank? | |
self.unit_amount = 0 if self.unit_amount.blank? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment