Topic: Standard Rails validation errors!? Receiving NoMethodError

Hi everyone,

I

Re: Standard Rails validation errors!? Receiving NoMethodError

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?  ...

Re: Standard Rails validation errors!? Receiving NoMethodError

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
-Select
-Collection_select
-options_from_collection_for_select

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")
    if @school.update_attributes(params[:school])
      flash[:notice] = 'School was successfully updated.'
      redirect_to :action => 'show', :id => @school
    else
      render :action => 'edit'
    end
  end

...yes it is obvious...welcome to my world...uggh!

Last edited by amendoza (2006-12-18 17:54:23)

Re: Standard Rails validation errors!? Receiving NoMethodError

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.

Re: Standard Rails validation errors!? Receiving NoMethodError

thanks danger.

Re: Standard Rails validation errors!? Receiving NoMethodError

Dangit - you beat me to it :-)

Way to figure it out!