Skip to content

Instantly share code, notes, and snippets.

@saroar
Last active June 21, 2016 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saroar/fb214e60995fd10e8899 to your computer and use it in GitHub Desktop.
Save saroar/fb214e60995fd10e8899 to your computer and use it in GitHub Desktop.
Create a list of the intervals of the day.
Field 1: Beginning of the day (From, the time in 24-hour format)
Field 2: End of the working day (Till, the 24-hour format)
Field 3: Divider partition hour intervals (integer, usually divider 60)
Button: Create a list of slots
class CreateWorkingDays < ActiveRecord::Migration
def change
create_table :working_days do |t|
t.datetime :start_of_day
t.datetime :end_of_day
t.integer :divider_partition_hour, default: 60
t.timestamps null: false
end
end
end
class WorkingDay < ActiveRecord::Base
has_many :slots, :dependent => :destroy
def slots_number
# binding.pry
total_minutes = (end_of_day - start_of_day) / 60
(total_minutes / divider_partition_hour).to_i
end
def create_slots
i = 0
while i < slots_number
# binding.pry
start = start_of_day + divider_partition_hour * i
i += 1
Slot.create(start_time: start, end_time: start + ( divider_partition_hour * 60 ), selected: false, working_day_id: id)
end
end
end
http://prntscr.com/9hrjja
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment