Module: ElocalApiSupport::Actions::Destroy

Defined in:
lib/elocal_api_support/actions/destroy.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/elocal_api_support/actions/destroy.rb', line 4

def destroy
  # record not found is ok for destroy
  render json: { errors: "Cannot retrieve record: #{params[:id]}" } and return \
    if lookup_object.nil?

  if lookup_object.destroy
    render json: lookup_object
  else
    render json: { errors: "Failed to destroy #{lookup_object}" }, status: 500
  end
rescue ActiveRecord::RecordNotFound
  # record not found is ok for destroy
  render json: { errors: "Cannot retrieve record: #{params[:id]}" }
end