Rails snippet: Making a ActiveRecord model save fail

This is the start of bunch of (hopefully) regular small posts with snippets for ruby and
rails. It’s supposed to be about those little things I keep looking up again and
again.

so back to topic: Making a rails model save fail!

  1. Add something to the errors in the validation

https://gist.github.com/4574361.js

  1. Make a before_filter fail (eg. before_create, …)
    Return false in a before_filter, will cause the model save to fail

https://gist.github.com/4574343.js

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.