Class: Gatherable::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/gatherable/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/gatherable/application_controller.rb', line 16

def create
  if data_table.new_record_strategy == :update
    model = model_class.find_or_initialize_by(global_id => global_id_val)
    model.update_attributes(model_params)
    render :json => model, :status => :ok
  else
    render :json => model_class.create!(model_params), :status => :created
  end
rescue StandardError => e
  render :json => { :errors => e.message}, :status => :unprocessable_entity
end

#destroyObject



37
38
39
40
41
42
# File 'app/controllers/gatherable/application_controller.rb', line 37

def destroy
  model_instance.delete
  head :no_content
rescue ActiveRecord::RecordNotFound => e
  render :json => { :errors => e.message}, :status => :not_found
end

#indexObject



6
7
8
# File 'app/controllers/gatherable/application_controller.rb', line 6

def index
  render :json => model_class.where(global_id => global_id_val), :status => :found
end

#showObject



10
11
12
13
14
# File 'app/controllers/gatherable/application_controller.rb', line 10

def show
  render :json => model_class.find_by!(global_id => global_id_val, model_id => params[model_id]), :status => :found
rescue ActiveRecord::RecordNotFound => e
  render :json => { :errors => e.message}, :status => :not_found
end

#updateObject



28
29
30
31
32
33
34
35
# File 'app/controllers/gatherable/application_controller.rb', line 28

def update
  model_instance.update_attributes!(model_params)
  render :json => model_instance, :status => :ok
rescue ActiveRecord::RecordNotFound => e
  render :json => { :errors => e.message}, :status => :not_found
rescue StandardError => e
  render :json => { :errors => e.message}, :status => :unprocessable_entity
end