class

ActiveRecord::MultiparameterAssignmentErrors

v1.0.0 - Show latest stable - Superclass: ActiveRecordError

No documentation available for this class.

Files

  • activerecord/lib/active_record/base.rb

2Notes

How to handle the MultiparameterAssignmentErrors exception

LacKac · Aug 4, 2008

If you expect to get this error, do this in your controller:

def create
@event = Event.new
@event.attributes = params[:event]
@event.save!
rescue ActiveRecord::MultiparameterAssignmentErrors => e
e.errors.each do |error|
  @event.errors.add(error.attribute, ActiveRecord::Errors.default_error_messages[:invalid])
end
rescue ActiveRecord::RecordInvalid
# event is invalid
ensure
if @event.errors.empty? and not @event.new_record?
  redirect_to event_path(@event)
else
  render :action => :new
end
end

If attribute assignment gives the +MultiparameterAssignmentErrors+ exception we handle it by adding 'invalid' errors to the attributes involved. We also rescue the +RecordInvalid+ exception and handle all the redirecting/rendering in the ensure block.

Alternative Way to Handle

rxcfc · May 22, 2009

This plugin may also help solve the problem from the model side.

http://github.com/rxcfc/multi_assignment_sanity