def confirm_invite_new_tutor
redirect_with_msg = false
@game_school = GameSchool.find(params[:id])
existing_user_emails = params[:all_emails][:existing_
everytime you use render
or redirect
in a controller, no part of the remaining code should have a render or redirect unless it's sure that it won't be passed. using your code
if new_users.present?
if @game_school.update_attributes(params[:param_game_school])
redirect_with_msg = true
else
render :invite_tutor_form
end
end
if validation fails when you update the attributes, you're running render :invite_tutor_form
. But the code will keep on running the next part of the code which is
if redirect_with_msg
redirect_to @game_school, notice: "daw"
else
redirect_to @game_school
end
so you get that error. The simplest solution is to add a return
after the call to render
if new_users.present?
if @game_school.update_attributes(params[:param_game_school])
redirect_with_msg = true
else
render :invite_tutor_form
return
end
end
Please do note that when you're doing more processing (like updating other attributes, or sending emails) after the if block that contains return
, those part of the code will not be executed.
add justand return
at the end of each redirect_to
or render
like below
`redirect_to @game_school and return`
This will work for you