Class: Observ::ScoresController

Inherits:
ApplicationController show all
Defined in:
app/controllers/observ/scores_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/observ/scores_controller.rb', line 7

def create
  value = parse_score_value(params[:value], params[:data_type])

  @score = @scoreable.scores.find_or_initialize_by(
    name: params[:name] || "manual",
    source: :manual
  )

  @score.assign_attributes(
    value: value,
    data_type: params[:data_type] || :boolean,
    comment: params[:comment],
    created_by: params[:created_by]
  )

  if @score.save
    respond_to do |format|
      format.turbo_stream
      format.html { redirect_back(fallback_location: root_path, notice: "Score saved.") }
    end
  else
    respond_to do |format|
      format.turbo_stream { render :create_error, status: :unprocessable_content }
      format.html { redirect_back(fallback_location: root_path, alert: "Failed to save score.") }
    end
  end
end

#destroyObject



35
36
37
38
39
40
41
42
43
# File 'app/controllers/observ/scores_controller.rb', line 35

def destroy
  @score = @scoreable.scores.find(params[:id])
  @score.destroy

  respond_to do |format|
    format.turbo_stream { render turbo_stream: turbo_stream.remove("score_#{@score.id}") }
    format.html { redirect_back(fallback_location: root_path, notice: "Score deleted.") }
  end
end