def update_preferences
        if @preferences_changed
          @preferences_changed.each do |group, preferences|
            group_id, group_type = Preference.split_group(group)
            
            preferences.keys.each do |name|
              # Find an existing preference or build a new one
              attributes = {:name => name, :group_id => group_id, :group_type => group_type}
              preference = find_preferences(attributes).first || stored_preferences.build(attributes)
              preference.value = preferred(name, group)
              preference.save!
            end
          end
          
          @preferences_changed.clear
        end
      end
def update_preferences
        if @preferences_changed
          @preferences_changed.each do |group, preferences|
            group_id, group_type = Preference.split_group(group)
            
            preferences.keys.each do |name|
              # Find an existing preference or build a new one
              attributes = {:name => name, :group_id => group_id, :group_type => group_type}
              preference = find_preferences(attributes).first || stored_preferences.build(attributes)
              preference.value = preferred(name, group)
              preference.save!
            end
          end
          
          @preferences_changed.clear
        end
      end
Updates any preferences that have been changed/added since the record
 was last saved