Module: RailsAdminImageManager::HasManagedFile

Defined in:
lib/rails_admin_image_manager/has_managed_file.rb

Instance Method Summary collapse

Instance Method Details

#has_managed_file(attribute, id, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rails_admin_image_manager/has_managed_file.rb', line 4

def has_managed_file(attribute, id, options={})
  var_options_name = "@has_managed_file_#{attribute}_options"
  var_options_value = instance_variable_get(var_options_name)

  # If the same attribute is passed twice, we'll skip it
  if var_options_value.nil?
    instance_variable_set(var_options_name, options)

    add_managed_file_belongs_to(attribute, managed_file_options_mandatory(options))
    add_managed_file_validates_presence_of(id) if managed_file_options_mandatory(options)
    add_managed_file_before_validation(attribute, id) unless managed_file_options_mandatory(options)
  end
end

#managed_file_is_mandatory?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/rails_admin_image_manager/has_managed_file.rb', line 18

def managed_file_is_mandatory?(attribute)
  validators_on(attribute).any?{|validator| validator.kind_of?(ActiveModel::Validations::PresenceValidator)}
end