Sha256: a36d5392617decd30277b85a4d9a7badf74448abb7a8c81154fe7da8f2e2f350

Contents?: true

Size: 906 Bytes

Versions: 3

Compression:

Stored size: 906 Bytes

Contents

module ElocalApiSupport
  module Actions
    module Update
      DEFAULT_IGNORED_PARAMETERS = %w(id created_at updated_at).freeze

      def update
        if lookup_object.update_attributes(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

      def parameters_to_ignore_from_update
        DEFAULT_IGNORED_PARAMETERS
      end

      def updatable_parameter_names
        associated_model.columns.map(&:name) - parameters_to_ignore_from_update
      end

      def parameters_available_for_update
        params[associated_model_name].permit(*updatable_parameter_names)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
elocal_api_support-1.0.0 lib/elocal_api_support/actions/update.rb
elocal_api_support-0.1.10 lib/elocal_api_support/actions/update.rb
elocal_api_support-0.1.9 lib/elocal_api_support/actions/update.rb