Module: ActiveRemote::Validations

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/active_remote/validations.rb

Instance Method Summary collapse

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(options = {})
  perform_validations(options) ? 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!(options = {})
  perform_validations(options) ? 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)

Returns:

  • (Boolean)


46
47
48
49
50
# File 'lib/active_remote/validations.rb', line 46

def valid?(context = nil)
  context ||= (new_record? ? :create : :update)
  output = super(context)
  errors.empty? && output
end