Module: ActiveRemote::Validations
Instance Method Summary collapse
-
#save(options = {}) ⇒ Object
Attempts to save the record like Persistence, but will run validations and return false if the record is invalid.
-
#save!(options = {}) ⇒ Object
Attempts to save the record like Persistence, but will raise ActiveRemote::RemoteRecordInvalid if the record is not valid.
-
#valid?(context = nil) ⇒ Boolean
(also: #validate)
Runs all the validations within the specified context.
Instance Method Details
#save(options = {}) ⇒ Object
Attempts to save the record like Persistence, but will run validations and return false if the record is invalid
Validations can be skipped by passing :validate => false
example Save a record
post.save
example Save a record, skip validations
post.save(:validate => false)
16 17 18 |
# File 'lib/active_remote/validations.rb', line 16 def save( = {}) perform_validations() ? super : false end |
#save!(options = {}) ⇒ Object
Attempts to save the record like Persistence, but will raise ActiveRemote::RemoteRecordInvalid if the record is not valid
Validations can be skipped by passing :validate => false
example Save a record, raise and error if invalid
post.save!
example Save a record, skip validations
post.save!(:validate => false)
31 32 33 |
# File 'lib/active_remote/validations.rb', line 31 def save!( = {}) perform_validations() ? super : raise_validation_error end |
#valid?(context = nil) ⇒ Boolean Also known as: validate
Runs all the validations within the specified context. Returns true if no errors are found, false otherwise.
Aliased as validate.
example Is the record valid?
post.valid?
example Is the record valid for creation?
post.valid?(:create)
46 47 48 49 50 |
# File 'lib/active_remote/validations.rb', line 46 def valid?(context = nil) context ||= (new_record? ? :create : :update) output = super errors.empty? && output end |