Reputation: 8451
I have an app that allows admins to create assignments and assign to workers on an account. This aspect works great but I'm trying to add a way for admins to set a schedule for when these assignments should be done. Things like how often(weekly, monthly, etc...) and how long the assignment should take (hours or mins). I started a little bit of this build out. Basically I set the attributes on assignment to include start_at
end_at
and frequency
. I'm not sure what to do with these attributes though. Has anybody built a system like this before? What are good gems or libraries I could use to help with this? Here is my schema for assignments:
create_table "assignments", force: :cascade do |t|
t.string "name"
t.string "description"
t.integer "account_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "attachment"
t.boolean "finished", default: false
t.integer "finished_count"
t.boolean "in_progress", default: false
t.datetime "start_at"
t.datetime "end_at"
t.string "frequency"
end
Upvotes: 0
Views: 35
Reputation: 10998
I think your approach is actually pretty good. That's what I would do. I would probably make the frequency
an enumerated type to include only certain values like: 'hourly, daily, weekly, monthly, yearly,' etc. This is easily accomplished by adding the following line to your model class in assignment.rb:
enum frequency: [ :hourly, :daily, :weekly, :monthly, :yearly ]
The way you've defined start_at
and end_at
is fine. Whenever the user accesses their assignment, you simply need to perform a query on the assignment to determine if it is in progress, past due, or not yet open.
Also, it looks like you're storing two boolean values called 'finished' and 'in_progress'. I would probably simplify those fields by creating another enumerated type called 'status' defined as follows:
enum status: [ :not_started, :in_progress, :finished ]
You'd need to remove the 'finished' and 'in_progress' columns from the table as well as add a field called 'title'. Create a migration file and paste the following code to modify the table:
def change
remove_column :assignments, :finished
remove_column :assignments, :in_progress
add_column :assignments, :status, :integer, default: 0
add_index :assignments, :status
end
That's what I would do, but that's just my opinion :) You'll need to code up how to determine whether an assignment is in progress or not by comparing the start and end times.
Upvotes: 1