daz13
daz13

Reputation: 245

Rails model validation not working

model:

validates :name, :presence => true
validates :year, :presence => true
validates :description, :presence => true

when submitting the form containing these fields, leaving the text boxes blank on purpose, instead of getting the Rails error messaging, I get the following exception thrown:

NoMethodError

You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each

Any thoughts on why this may occur would be greatly appreciated.

Upvotes: 0

Views: 1975

Answers (1)

Adam
Adam

Reputation: 821

A stab in the dark would be that its not your validations throwing the error message. My first instinct is that its the error view code (if you are looping through the errors the nil is possibly in there). Its also possible its an error in the controller but I would have to see the first couple lines of the backtrace to make a more informed guess.

Upvotes: 1

Related Questions