what is the difference save() vs save!()

Hi,
Can anyone please tell me the difference between save & save!() method

Anything with an exclamation with raise an error if it is not successful, without an exclamation it will just return false

RobL

Palani Kumar wrote:

Hi --

Palani Kumar wrote:

Hi,
Can anyone please tell me the difference between save & save!() method

Anything with an exclamation with raise an error if it is not
successful, without an exclamation it will just return false

RobL

I'd just add, to clarify, that that's a Rails idiom, not a
Ruby-language one (i.e., the ! doesn't actually cause the error).

Anyone who's interested can find an in-depth explanation of !-methods
here:

http://dablog.rubypal.com/2007/8/15/bang-methods-or-danger-will-rubyist

That post talks about the Ruby conventions, as delineated by Matz and
practiced in Ruby itself. Rails doesn't follow those conventions but,
with all due respect to the Rails team, I wish it did :slight_smile: and I
strongly recommend following the conventions when you choose method
names in your own code.

David