results_controller.rb 1.58 KB
Newer Older
Sara Kuqi's avatar
Sara Kuqi committed
1
class ResultsController < ApplicationController
pei-chi.huang's avatar
pei-chi.huang committed
2
  before_action :authenticate_user!
Sara Kuqi's avatar
Sara Kuqi committed
3
4
  before_action :set_result, only: [:show, :edit, :update, :destroy]

Sara Kuqi's avatar
Sara Kuqi committed
5
  def new
Sara Kuqi's avatar
Sara Kuqi committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    @result = Result.new
  end

  def index
    @results = Result.all
  end

  def show
  end

  def edit
  end

  def create
    @result = Result.new(result_params)
21

Sara Kuqi's avatar
Sara Kuqi committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
    respond_to do |format|
      if @result.save
        format.html { redirect_to @result, notice: 'Result was successfully created.' }
        format.json { render :show, status: :created, location: @result }
      else
        format.html { render :new }
        format.json { render json: @result.errors, status: :unprocessable_entity }
      end
    end
  end

  def update
    @result = Result.find(result_params[:result_id])
    @result.row_order_position = result_params[:row_order_position]
    respond_to do |format|
      if @result.update(result_params)
        format.html { redirect_to @result, notice: 'Result was successfully updated.' }
        format.json { render :show, status: :ok, location: @result }
      else
        format.html { render :edit }
        format.json { render json: @result.errors, status: :unprocessable_entity }
      end
    end
  end

  def destroy
    @result.destroy
    respond_to do |format|
      format.html { redirect_to results_url, notice: 'Result was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private

  def set_result
    @result = Result.find(params[:id])
  end
  def result_params
61
    params.require(:result).permit(:sample_id, :measurement, :name)
Sara Kuqi's avatar
Sara Kuqi committed
62
    params.fetch(:result, {})
Sara Kuqi's avatar
Sara Kuqi committed
63
64
  end
end