1
イベントの開始時間と終了時間の間の時間を計算しようとしています。ユーザーがイベントにサインアップすると、目標に向かって進みます。今私は負の数を取得している以外は、メソッドが動作するようです。私はそれがコード開始時間と終了時間の間の計算時間
h = ((event.start_time - event.end_time)/1.hour).round
のこの行とは何かここで誰かがこれで私を助けることができる期待して、このモデルのために私の全体のコントローラだだと仮定しています。
class UserEventsController < ApplicationController
def create
event = Event.find(params[:id])
current_user.events << event
hours = 0
goals = current_user.goals
current_user.events.each do |event|
h = ((event.start_time - event.end_time)/1.hour).round
hours += h
current_user.update_attributes(hours: h)
end
redirect_to organization_path(event.organization)
end
end
これは完璧です!どうもありがとうございます ! – Amena