0

私のRailsアプリケーションには、Userモデル、Departmentモデル、Groupモデル、およびRegisterモデルがあります.Userモデルには基本的なユーザー情報があり、

ユーザー モデル:

id , name
has_and_belongs_to_many :departments , :groups

部門モデル:

id,name
has_and_belongs_to_many :users
has_many :registers

グループ モデル:

id,name
has_and_belongs_to_many :users
has_many :registers

登録モデル:

date ,department_id , group_id , one , two , three
belongs_to :department ,:group

登録モデルの中で、「1」、「2」、「3」は時間枠で、9-12、12-3、3-6 とします。毎日、各ユーザーは出席をマークする必要があるため、時間に対して出席をマークする必要があります。レジスタ テーブルのスロット。タイムスロットで現在の時間に基づいて出席をマークする方法。

前もって感謝します。

4

3 に答える 3

1

あなたがする必要があるかもしれません

current_time = Time.now
if (9..11).include?(current_time.hour)
# Do A
elsif (12..14).include?(current_time.hour)
# Do B
elsif (15..18).include?(current_time.hour)
# Do C
end

(また)

current_time = Time.now
if (9...12).include?(current_time.hour)
# Do A
elsif (12...15).include?(current_time.hour)
# Do B
elsif (15...18).include?(current_time.hour)
# Do C
end
# I think of the extra "." as 'eating' the last value so you don't have it.

重複に対処する

于 2012-12-20T05:53:42.370 に答える
1

これを試して

current_time = Time.now
if (9..12).include?(current_time.hour)
# 9-12
elsif (12..15).include?(current_time.hour)
# 12-3
elsif (15..18).include?(current_time.hour)
# 3-6
end
于 2012-12-20T05:29:08.263 に答える
0

ビットマップの作成を検討してください。32 ビット整数は軽量で、1 時間ごとに 1 つずつ、0 から 24 を返します。時間の範囲を比較、設定、...できる関数を書きます。

于 2012-12-20T05:20:38.063 に答える