Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/scaffold_markup/extensions/active_record_extension.rb

Class Method Summary collapse

Class Method Details

.accessible_attribute_namesObject



6
7
8
# File 'lib/scaffold_markup/extensions/active_record_extension.rb', line 6

def self.accessible_attribute_names
  accessible_attributes.to_a.select { |a| a.present? }
end

.reflected_association(attribute) ⇒ Object



2
3
4
# File 'lib/scaffold_markup/extensions/active_record_extension.rb', line 2

def self.reflected_association(attribute)
  reflections.map { |k, v| v }.select { |e| e.foreign_key == attribute.to_s }.first
end

.validates_presence?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/scaffold_markup/extensions/active_record_extension.rb', line 10

def self.validates_presence?(attribute)
  validator = validators.select { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }.first
  validator && (validator.attributes.include?(attribute.to_sym) || validator.attributes.include?(attribute.to_s))
end