当前位置: 动力学知识库 > 问答 > 编程问答 >

Signing up for recurring events in Ruby on Rails (Using schedulable gem)

问题描述:

I am building out a Ruby on Rails application that will allow a Player to sign up for Game. Currently, I have it setup to be a has_and_belongs_to_many relationship because a game might have several players and a player might be signed up for several games. Additionally, games are RECURRING events which can only be created by a Facility. (Facilities have_many games). I am handling the recurring events using the schedulable gem.

Game Model:

class Game < ActiveRecord::Base

belongs_to :facility

has_and_belongs_to_many :players

acts_as_schedulable :schedule

end

If I return a specific game and save it to @game, and then call @game.schedule it will return something like this:

#<Schedule:0x007fdc34265710

id: 4,

schedulable_id: 9,

schedulable_type: "Game",

date: Fri, 24 Feb 2017,

time: 2000-01-01 12:30:00 UTC,

rule: "weekly",

interval: "1",

day: ["tuesday", "thursday"],

day_of_week: {"monday"=>[""], "tuesday"=>[""], "wednesday"=>[""], thursday"=>[""], "friday"=>[""], "saturday"=>[""], "sunday"=>[""]},

until: nil,

count: 0,

created_at: Fri, 24 Feb 2017 15:25:03 UTC +00:00,

updated_at: Fri, 24 Feb 2017 15:25:03 UTC +00:00>

Furthermore, I can call occurrences like so @game.schedule.occurrences(Time.now + 1.year) and it will return all of the occurrences in an Array from now until next year.

I'm not exactly sure how to model this. Are Players signing up for a Game, a Schedule or an Occurrence? Currently, I only have a Model for Game and Schedule. I'd eventually like to see all players that are signed up for a specific game instance (occurrence). Thoughts? Thank you!

分享给朋友:
您可能感兴趣的文章:
随机阅读: