Sounds like the model object itself is nil. You might need to
implement your controller like this:
def index
@user = User.new()
if request.post?
@user = User.new(params[:user])
# do the validation and save
end
end
So that way the view has everything it needs on first go, but on post
and validation failure it can still ''remember'' the contents of
the
form.
Cheers,
Dan
On 7/17/05, Greg Donald <destiney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I''m trying to provide individual error messages under the field
the
> message applies to.
>
> In my model I have:
>
> def validate
> errors.add(:name, "Should not be blank") if name.nil?
> end
>
> Then in my template I have:
>
> <%= error_message_on(:user, :name) || '''' %>
>
> The problem is when I first load the form I get this warning message:
>
> WARNING: You have a nil object when you probably didn''t expect
it!
> Odds are you
> want an instance of ActiveRecord::Base instead.
>
> How can I test for errors properly on both form load and on redisplay
> when errors occur? I don''t want a big block of errors at the top
of
> the page, I''m wanting individual errors near the form fields.
>
> Thanks,
>
> --
> Greg Donald
> Zend Certified Engineer
> MySQL Core Certification
> http://destiney.com/
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>