Skip to content

Commit

Permalink
Update lectures_controller.rb
Browse files Browse the repository at this point in the history
If a lecture had no editors the old code would perform actions on a nil object causing an error.
Now the relevant passage in the update method is surrounded by an if-statement which first checks, if the given array of editor ids is nil and skips the passage in this case.
  • Loading branch information
Frodo161 authored Jan 15, 2023
1 parent 0cd16c5 commit 3792ed8
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions app/controllers/lectures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,23 @@ def edit
end

def update
# removes the empty String "" in the NEW array of editor ids
# and converts it into an array of integers
all_ids = lecture_params[:editor_ids].map(&:to_i) - [0]
old_ids = @lecture.editor_ids
new_ids = all_ids - old_ids

# returns an array of Users that match the given ids
recipients = User.where(id: new_ids)

recipients.each do |r|
NotificationMailer.with(recipient: r,
locale: r.locale,
lecture: @lecture)
.new_editor_email.deliver_later
editor_ids = lecture_params[:editor_ids]
if editor_ids != nil
# removes the empty String "" in the NEW array of editor ids
# and converts it into an array of integers
all_ids = editor_ids.map(&:to_i) - [0]
old_ids = @lecture.editor_ids
new_ids = all_ids - old_ids

# returns an array of Users that match the given ids
recipients = User.where(id: new_ids)

recipients.each do |r|
NotificationMailer.with(recipient: r,
locale: r.locale,
lecture: @lecture)
.new_editor_email.deliver_later
end
end

@lecture.update(lecture_params)
Expand Down

0 comments on commit 3792ed8

Please sign in to comment.