module ElocalApiSupport::Actions::Update

Constants

DEFAULT_IGNORED_PARAMETERS

Public Instance Methods

update() click to toggle source
# File lib/elocal_api_support/actions/update.rb, line 8
def update
  if lookup_object.update(parameters_available_for_update)
    render json: lookup_object
  else
    Rails.logger.info { "There was an issue updating model #{lookup_object}" }
    Rails.logger.debug { "Error details #{lookup_object.errors.to_xml}" }
    render json: { errors: lookup_object.errors }, status: 422
  end
end

Private Instance Methods

parameters_available_for_update() click to toggle source
# File lib/elocal_api_support/actions/update.rb, line 32
def parameters_available_for_update
  params[associated_model_name].permit(*updatable_parameter_names)
end
parameters_to_ignore_from_update() click to toggle source
# File lib/elocal_api_support/actions/update.rb, line 20
def parameters_to_ignore_from_update
  DEFAULT_IGNORED_PARAMETERS
end
updatable_parameter_names() click to toggle source
# File lib/elocal_api_support/actions/update.rb, line 24
def updatable_parameter_names
  associated_model.columns.map do |col|
    next if col.name.in?(parameters_to_ignore_from_update)

    col.array ? { col.name => [] } : col.name
  end
end