How To Skip Rails Validations On Save

Of course this is a bad practice, but once in a while you need to skip validations and callbacks when saving a Rails object.

For my use case today, I needed to go back through existing records and change the values for a few fields. Going forward, there are now new validations to make sure new objects have the correct values for these fields, but going back required skipping these new validations.

Here is how simple it is to skip validations when saving an object in Rails:!(:validate => false)

Remember, with great power comes great responsibility. So use responsibly!

Enjoy the article? Join over 20,000+ Swift developers and enthusiasts who get my weekly updates.

  • kerry

    Hi Natasha, i just bought your book- and I’m very interested in learning to program. if i’m a 43 year old woman – albeit a young looking one – am i too old to get a job as a software developer?

    • Hi Kerry,

      Of course you can get a job as a software developer! That’s what I love about this profession – your code determines your qualifications, not your age or gender or ethnicity, etc.

      Dev Bootcamp, for example, always has a few students in their 40s, and I’m always most impressed by that. I wish that when I’m 40, I’d be adventurous and curious to take a risk like that and launch something completely new!

      Here is an article in Wired about my colleague from Dev Bootcamp (who’s in his 40s), who went from being a lawyer to being employed as a Software Developer: I’ll email you an introduction if you’re interested.

      • kerry

        Thanks, Natasha! I’m reading your book and taking the steps necessary… 🙂

  • This method is for rails 3 and above,
    If you want to skip individual validation then you need to do somehing like