-
Notifications
You must be signed in to change notification settings - Fork 362
IceCube and Rails
sstarr edited this page Mar 15, 2012
·
5 revisions
If you are using Bundler include ice_cube by adding gem 'ice_cube'
to your Gemfile and running bundle install
.
Then add include IceCube
inside and at the top of your ActiveRecord model file to use the IceCube classes easily.
For example:
class Task < ActiveRecord::Base
include IceCube
def schedule
new_schedule = Schedule.new(start_date)
new_schedule.add_recurrence_time(Time.now)
new_schedule.add_exception_time(Time.now + 1.day)
return new_schedule
end
end
Say you want to save your schedule in an ActiveRecord model with the attribute name 'schedule' using the to_hash rather than the to_yaml serialization you should set up your model like so:
class Task < ActiveRecord::Base
include IceCube
serialize :schedule, Hash
def schedule=(new_schedule)
write_attribute(:schedule, new_schedule.to_hash)
end
def schedule
Schedule.from_hash(read_attribute(:schedule))
end
end