Skip to content

Commit

Permalink
Use save(validate: false) on internal saves, this way we don't mess…
Browse files Browse the repository at this point in the history
… up with invalid models.
  • Loading branch information
swanandp committed Feb 22, 2014
1 parent 053ac51 commit 7390b48
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/acts_as_list/active_record/acts/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ def default_position?

# Sets the new position and saves it
def set_list_position(new_position)
send("#{position_column}=", new_position)
save!
write_attribute position_column, new_position

This comment has been minimized.

Copy link
@orbanbotond

orbanbotond Sep 2, 2015

Update_column would be a better solution because it doesn't modified the updated_at which in turn invalidates the caching...

save(validate: false)
end

private
Expand Down

2 comments on commit 7390b48

@zarqman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this cause the entire invalid model to be saved though, not just the new position? IMHO, puking on a position change is preferable to accidentally persisting unrelated, invalid data.

@romanbsd
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do:

persisted? ? update_column(position_column, new_position) : update_attribute(position_column, new_position)

Please sign in to comment.