You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a model "Exam", each exam will have a schedule (Montrose::Schedule) which has lots of recurrences. For exam, an exam has a schedule with 2 recurrences:
from '12-23-2024' to '12-23-2025' at 9:30am every Monday
from '01-01-2026' to '01-31-2026' at 4:00pm every Sunday
If a user wants to edit the first recurrence, what my code will do is to find which record matches the selected recurrence and remove that record, then create a new one based on the new fields. My code looks like below:
class ExamController
def update
exam = Exam.find(params[exam_id])
target_recurrence_index = -1
exam.schedule.rules.each_with_index do |r, index|
# compare starts, until, at and on of "r" and "edit_recurrence_param", if all same, set target_recurrence = index
end
if target_recurrence_index >= 0
exam.schedule.rules.delete_at(target_recurrence_index)
edited_recurrence = Montrose::Recurrence.new(edit_recurrence_param)
exam.schedule << edited_recurrence
end
end
private
def edit_recurrence_param
params.permit(::every, :starts, :until, :at, :on)
end
end
I think this is a very bad way to do the edition, what could be the best practice to edit a recurrence? Any help would be appreciated!
The text was updated successfully, but these errors were encountered:
Hi,
I have a model "Exam", each exam will have a schedule (Montrose::Schedule) which has lots of recurrences. For exam, an exam has a schedule with 2 recurrences:
If a user wants to edit the first recurrence, what my code will do is to find which record matches the selected recurrence and remove that record, then create a new one based on the new fields. My code looks like below:
I think this is a very bad way to do the edition, what could be the best practice to edit a recurrence? Any help would be appreciated!
The text was updated successfully, but these errors were encountered: