Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skipping validation on create method

I need to skip the validation on create method.I am using Rails 4 and ruby 2

i have tried like this

@model.save(:validate => false)

it not working

like image 966
chandramouli Avatar asked Sep 10 '13 12:09

chandramouli


People also ask

How does validation work in Rails?

Rails validation defines valid states for each of your Active Record model classes. They are used to ensure that only valid details are entered into your database. Rails make it easy to add validations to your model classes and allows you to create your own validation methods as well.


1 Answers

Assuming you are talking about ActiveRecord; In Rails 3 and 4 the way to skip validations and potentially persist invalid objects is as you describe:

@model.save(:validate => false)

In Rails 2 you'd need to do

@model.save(false)
like image 172
Jakob S Avatar answered Nov 07 '22 02:11

Jakob S