class Madmin::Field
Attributes
attribute_name[R]
model[R]
options[R]
Public Class Methods
field_type()
click to toggle source
# File lib/madmin/field.rb, line 5 def self.field_type to_s.split("::").last.underscore end
new(attribute_name:, model:, **options)
click to toggle source
# File lib/madmin/field.rb, line 9 def initialize(attribute_name:, model:, **options) @attribute_name = attribute_name @model = model @options = options end
Public Instance Methods
required?()
click to toggle source
# File lib/madmin/field.rb, line 36 def required? model.validators_on(attribute_name).any? { |v| v.is_a? ActiveModel::Validations::PresenceValidator } end
searchable?()
click to toggle source
# File lib/madmin/field.rb, line 40 def searchable? false end
to_param()
click to toggle source
# File lib/madmin/field.rb, line 27 def to_param attribute_name end
to_partial_path(name)
click to toggle source
# File lib/madmin/field.rb, line 19 def to_partial_path(name) unless %w[index show form].include? name raise ArgumentError, "`partial` must be 'index', 'show', or 'form'" end "/madmin/fields/#{self.class.field_type}/#{name}" end
value(record)
click to toggle source
# File lib/madmin/field.rb, line 15 def value(record) record.public_send(attribute_name) end
visible?(action, default: true)
click to toggle source
Used for checking visibility of attribute on an view
# File lib/madmin/field.rb, line 32 def visible?(action, default: true) options.fetch(action.to_sym, default) end