Use bang methods

Use Active Record bang methods like update!, create! or save! over their counterparts when we are not checking the return value of those methods.

def assign_roles_to_project_users(project_roles, role)
  if role && OrganizationUser.can_assign_projects_to_role?(role) && project_roles
    user.project_users.each do |project_user|
        project_user.update(role: 'regular_user')
    end
  end
end

If we are not Using bang version then that would lead to an inconsistent state. It’s better to fail and raise an exception when there is no easy way to handle error.

This strategy is also applicable to writing tests. Often we are trying to get data in the right state before actually doing the testing. In such cases while we are building the data we should use update! and create!.

If we are handling the case when record is not persisted then there is no need to use bang version.

if post.save
  puts "Success!"
else
  puts "Failed!"
end