Topic: What does to_hash do? Building business hour schedule structure

I'm learning rails and I'm trying to figure out a structure for business hours. I found that Ice Cube gem has recurring schedules and I was looking at their wiki page and they said that if I have an attribute 'schedule' that I should use to_hash rather than the to_yaml.

But I'm new to rails and I'm trying to figure out what to_hash does? Is it supposed to just save your schedule to only 1 record?

My model looks like this:

class Hour < ActiveRecord::Base
  attr_accessible :schedule
  include IceCube
  belongs_to :hourable, polymorphic: true
  serialize :schedule, Hash

  def schedule=(new_schedule)
    write_attribute(:schedule, new_schedule.to_hash)

  def schedule

And this is my migration

class CreateHours < ActiveRecord::Migration
  def change
    create_table :hours do |t|
      t.string :schedule
      t.belongs_to :hourable, polymorphic: true

    add_index :hours, [:hourable_id, :hourable_type]


Am I doing this correctly? If I create a page where user can set their schedule, it'll just save it into one string, the schedule column?

Thanks for your help!

Last edited by andrewliu (2013-06-25 00:19:26)