Flowdock

No documentation

This class has no description. You can help the Ruby on Rails community by adding new notes.

Show files where this class is defined (1 file)
Register or log in to add new notes.
August 4, 2008
0 thanks

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.

May 22, 2009
0 thanks

Alternative Way to Handle

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

http://github.com/rxcfc/multi_assignment_sanity