Guest User

Untitled

a guest
May 26th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. class TestsController < ApplicationController
  2. before_action :set_test, only: [:show, :edit, :update, :destroy]
  3.  
  4. # GET /tests
  5. # GET /tests.json
  6. def index
  7. @tests = Test.all
  8. end
  9.  
  10. # GET /tests/1
  11. # GET /tests/1.json
  12. def show
  13. end
  14.  
  15. # GET /tests/new
  16. def new
  17. @test = Test.new
  18. end
  19.  
  20. # GET /tests/1/edit
  21. def edit
  22. end
  23.  
  24. # POST /tests
  25. # POST /tests.json
  26. def create
  27. @test = Test.new(test_params)
  28.  
  29. respond_to do |format|
  30. if @test.save
  31. format.html { redirect_to @test, notice: 'Test was successfully created.' }
  32. format.json { render :show, status: :created, location: @test }
  33. else
  34. format.html { render :new }
  35. format.json { render json: @test.errors, status: :unprocessable_entity }
  36. end
  37. end
  38. end
  39.  
  40. # PATCH/PUT /tests/1
  41. # PATCH/PUT /tests/1.json
  42. def update
  43. respond_to do |format|
  44. if @test.update(test_params)
  45. format.html { redirect_to @test, notice: 'Test was successfully updated.' }
  46. format.json { render :show, status: :ok, location: @test }
  47. else
  48. format.html { render :edit }
  49. format.json { render json: @test.errors, status: :unprocessable_entity }
  50. end
  51. end
  52. end
  53.  
  54. # DELETE /tests/1
  55. # DELETE /tests/1.json
  56. def destroy
  57. @test.destroy
  58. respond_to do |format|
  59. format.html { redirect_to tests_url, notice: 'Test was successfully destroyed.' }
  60. format.json { head :no_content }
  61. end
  62. end
  63.  
  64. private
  65. # Use callbacks to share common setup or constraints between actions.
  66. def set_test
  67. @test = Test.find(params[:id])
  68. end
  69.  
  70. # Never trust parameters from the scary internet, only allow the white list through.
  71. def test_params
  72. params.fetch(:test, {})
  73. end
  74. end
Add Comment
Please, Sign In to add comment