Skip to content

Instantly share code, notes, and snippets.

@acook
Created February 12, 2014 00:37
Show Gist options
  • Save acook/5c6bec19d016fbf79762 to your computer and use it in GitHub Desktop.
Save acook/5c6bec19d016fbf79762 to your computer and use it in GitHub Desktop.
Names changed to protect the guilty.
class ThingyThing
include Virtus
extend ActiveModel::Naming
include ActiveModel::Validations
include ActiveModel::Conversion
attribute :thing, thing
def persisted?
false
end
validate do
unless thing.valid?
thing.errors.each do |key, value|
errors[key] << value
end
end
end
def save
unless valid?
Rails.logger.warn("ERROR - #{errors.inspect}")
return false
end
thing.save
rescue => e
Rails.logger.error "----------"
Rails.logger.error e
Rails.logger.warn("ERROR - #{errors.inspect}")
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment