Checkboxes array to delete images
I try to start from part dealing with removing of checked attachments.

First, I can't find purpose of puts lines. Only if it used for debugging in development.

Second, @lesson.attachments.each.with_index - every time updating single attachment, you need to go through all existing records. I think, that is what 'Codeclimate' "says". So, that structure must be simplified.

Here is how I suggest to rewrite 'deletion' part:

def update

  params[:delete_array].try :each do |id|
    @lesson.attachments.find(id).destroy
  end

# other code

end


Other parts (for params[:order_array] and params[:description_array]) can be refactored in the same way. I hope, you've got the idea.

If you need more detailed explanation of above code or need help with other parts - let me know and I'll explain it in details.