Topic: Standard Rails validation errors!? Receiving NoMethodError
This is an archive from Rails Forum. Check out the new community here!
A forum for Ruby on Rails users
weak...I have to regenerate the scaffold and restore the _form.rhtml and `schools` controller from cp's...but up and validating. Why?
... a better way? ...
Ok, I figured it out.
This problem had nothing to do with the migration of the database.(that just threw me off)
If you are going to use a select method in your forms like
and you still want your models validations to work, the find() method for your selection must be available to all pieces (like create/update/new/edit) if there is a redirect due to the validate_whatever.
So in my little example the critical missing piece (*) was
def update /create
@School = School.find(params[:id])
*-> @schooltypes = Schooltype.find(:all, :order => "name")
flash[:notice] = 'School was successfully updated.'
redirect_to :action => 'show', :id => @school
render :action => 'edit'
...yes it is obvious...welcome to my world...uggh!
Last edited by amendoza (2006-12-18 17:54:23)
The problem was that the 'update' method didn't set the @schooltypes array. So when you went to do:
<%= select ('school', 'schooltype_id', @schooltypes) %>
The 'select' method started treating @schooltypes like an array - but it was actually nil.
The solution to this would be to add @schooltypes to your 'update' method in the controller.
Hosting provided by aTech Media