Hey Guys,
Ive just set up some basic models using scaffold with Rails, i've edited the views so that im taking input from a textfield and a selection box. Here are some code snippets:
form_for(@town) do |f|
f.text_field :name
.
.
f.select :county_id, @counties.map{|c| [c.name, c.id]}
.
.
end
Using the validation method "validates_presence_of" for the textfield and no validation on the selection box I can enter values and successfully write to the database. When I try to test validation by not entering anything into the textfield, I get a NoMethodError with the following message
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.map
Note: there is no validation on the selection box
If I comment out the "validate_presence_of" line I can write blank data to the db with no problems. However if I write validate code for the textfield and it cause the entire form object becomes nil apparently...is Rails' validation causing this?
Any thoughts/comments are greatly appreciated. Im using Rails 2.3.4