Save What's Valid

Rails' default update_attributes behavior is that when any validation fails, none of the data gets saved. However, in some instances this is not the most ideal behavior. If you import partial data which users then have the task of completing, not saving partially completed forms can create a really negative user experience and decrease overall completion (or conversion) rates.

For example, some users complained when their incomplete changes didn't stick bceause they had intended to send the remainder of the form to a colleague to complete the rest.

This gem encapsulates the logic I've used to ensure that partially completed forms still persist.

Usage

class Person < ActiveRecord::Base

  # Include the module.
  include SaveWhatsValid

  # These are the attributes available on the model.
  attr_accessible :age, :description, :first_name, :last_name, :middle_initial

  # These two attributes are required.
  validates_presence_of :first_name
  validates_presence_of :last_name

  # These are the attributes we want to save any valid value for.
  save_whats_valid :age, :description, :first_name, :last_name

end