chandramouli
chandramouli

Reputation: 245

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

Upvotes: 14

Views: 27534

Answers (3)

Jakob S
Jakob S

Reputation: 20145

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)

Upvotes: 13

Miotsu
Miotsu

Reputation: 1776

validates :some_attr, :presence => true, :unless => :create

skips the validation JUST for create.

Upvotes: 1

techvineet
techvineet

Reputation: 5111

You can do this in model by

validates :some_attr, :presence => true, :on => :update

Upvotes: 4

Related Questions