Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

errors[:base] is cleared when entering model

#6350

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.

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

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Nico Schottelius
    Nico Schottelius

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

    January 31st, 2011 @ 01:48 PM

  2. rails
    rails
    • 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.

    May 1st, 2011 @ 01:00 AM

  3. rails
    rails
    • State changed from open to stale

    May 1st, 2011 @ 01:00 AM

  4. af001
    af001

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

    May 5th, 2011 @ 02:55 AM