Class: SupplejackApi::Harvester::ConceptsController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/supplejack_api/harvester/concepts_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/supplejack_api/harvester/concepts_controller.rb', line 14

def create
  if params[:preview]
    klass = SupplejackApi::PreviewRecord
    attribute = :record_id
  else
    klass = SupplejackApi::Concept
    attribute = :concept_id
  end

  @concept = klass.find_or_initialize_by_identifier(params[:concept])
  @concept.set_status(params[:required_fragments])
  @concept.create_or_update_fragment(params[:concept])
  @concept.save
  @concept.unset_null_fields

  render json: { attribute => @concept.concept_id }
end

#updateObject


32
33
34
35
36
37
38
# File 'app/controllers/supplejack_api/harvester/concepts_controller.rb', line 32

def update
  @concept = Concept.custom_find(params[:id], nil, status: :all)
  if params[:concept].present? && params[:concept][:status].present?
    @concept.update_attribute(:status, params[:concept][:status])
  end
  respond_with @concept
end