Advertisement
Guest User

Untitled

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