This project is archived and is in readonly mode.

#6350 ✓stale
Nico Schottelius

errors[:base] is cleared when entering model

Reported by Nico Schottelius | January 31st, 2011 @ 01:46 PM

Hello,

when using

@booking.errors.add(:base, "Only " + reservable_machines_count.to_s + " " + MachineType.find(type).name + "(s) available at the choosen date.")

or

@booking.errors[:base] << "Trying to book more " + typename + "s than existing."

in the controller, results in an empty array in the validation methods of
the booking model. I do not call errors.clear.

Example code:

controller:
# returns string from above (correctly) puts "Errors before calling model" + @booking.errors[:base].to_s ... respond_to do |format|

  if @booking.save
     format.html { redirect_to(@booking, :notice => 'Booking successfully created.') }
     format.xml  { render :xml => @booking, :status => :created, :location => @booking }
  else
     # this line only contains the errors setup within the model, original ones are gone. (WRONG)
     puts "Errors after model" + @booking.errors[:base].to_s

model:

validate :has_one_or_more_reservations

def has_one_or_more_reservations

  # this one is empty as well
  puts "printing errors : " + errors[:base].to_s
  errors[:base] << "No machine selected" if (reservations.nil? or reservations.empty?)

end

Actual codebase can be found on http://git.schottelius.org/?p=mbs;a=summary.

Tested with rails 3.0.0 and 3.0.3.

Comments and changes to this ticket

  • Nico Schottelius

    Nico Schottelius January 31st, 2011 @ 01:48 PM

    According to http://juixe.com/techknow/index.php/2006/08/06/raising-model-errors...
    this should work (and I think it used to work in rails2), according to http://guides.rubyonrails.org/active_record_validations_callbacks.h... the behaviour is not defined, though it would make sense if it works (again).

  • rails

    rails May 1st, 2011 @ 01:00 AM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • rails

    rails May 1st, 2011 @ 01:00 AM

    • State changed from “open” to “stale”
  • af001

    af001 May 5th, 2011 @ 02:55 AM

    私の中で、総合評価のとっても低いアバアバクロホリスタークロ銀座店。アバクロは大好きなんですけどね。一昨日の東京駅付近での打ち合わせの後、散歩がてら久々に行ってきました。そしたらビックリ!相変わらアバクロず、踊っているだけの店員さんとかもいましたが、

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages