Re: nil.errors and error_messages_for

bongoman
Thu, 26 Mar 2009 04:57:04 -0000

> So... uh... @discount indeed contains a stuffed Discount instance
with populated
> errors... so what''s the problem??

Well it only does when the index template is rendered AFTER validation
fails. The same action gets invoked prior to the form submission at
which point in time there is no @discount variable, hence the
nil.errors

> So post your actual action instead of making us guess? (-8

Here we go:

    @discount = Discount.find(params[:id])
    if @discount.update_attributes(params[:discount])
      flash[:notice_good] = "Discounts have been updated"
      redirect_to :action=> ''index''
    else
      index # I need to do this in order to get my instance variables
populated for the index view
      render :action => ''index''
    end