Raised when there are multiple errors while doing a mass assignment through the {ActiveRecord::Base#attributes=}[rdoc-ref:AttributeAssignment#attributes=] method. The exception has an errors property that contains an array of AttributeAssignmentError objects, each corresponding to the error while assigning to an attribute.
How to handle the MultiparameterAssignmentErrors exception
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
This plugin may also help solve the problem from the model side.
http://github.com/rxcfc/multi_assignment_sanity