Skip to content

Instantly share code, notes, and snippets.

@kenton
Created April 26, 2012 16:19
Show Gist options
  • Save kenton/2500699 to your computer and use it in GitHub Desktop.
Save kenton/2500699 to your computer and use it in GitHub Desktop.
# saving tiers to the DB
> market = OndemandMarket.first
> market.pricing_tiers = { :first_five_minutes => 3.0, :second_five_minutes => 2.5, :additional_minutes => 1.0 }
> market.save
# pulling tiers from the DB
> market.pricing_tiers
{ :first_five_minutes => 3.0, :second_five_minutes => 2.5, :additional_minutes => 1.0 }
# to update rows on a table
> OndemandMarket.all.each do |m|
m.pricing_tiers = {:first_five_minutes => 3.0, :second_five_minutes => 2.5, :additional_minutes => 1.0}
m.ten_mile_multiplier = 1.5
m.twenty_mile_multiplier = 1.75
m.time_factor = 2.0
m.save
end
# update one row at a time
> m = OndemandMarket.find(1)
# replace the "1" with the ID for whatever record you want to update
> m.update_attributes!(:pricing_tiers => {:first_five_minutes => 3.0, :second_five_minutes => 2.5, :additional_minutes => 1.0}, :ten_mile_multiplier => 1.5, :twenty_mile_multiplier => 1.75, :time_factor => 2.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment