Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.77 KB | None | 0 0
  1. class TasksController < ApplicationController
  2.   before_action :set_task, only: [:show, :edit, :update, :destroy]
  3.  
  4.   # GET /tasks
  5.   # GET /tasks.json
  6.   def index
  7.     @tasks = Task.all
  8.   end
  9.  
  10.   # GET /tasks/1
  11.   # GET /tasks/1.json
  12.   def show
  13.   end
  14.  
  15.   # GET /tasks/new
  16.   def new
  17.     @task = Task.new
  18.   end
  19.  
  20.   # GET /tasks/1/edit
  21.   def edit
  22.   end
  23.  
  24.   # POST /tasks
  25.   # POST /tasks.json
  26.   def create
  27.     @task = Task.new(task_params)
  28.  
  29.     respond_to do |format|
  30.       if @task.save
  31.         format.html { redirect_to @task, notice: 'Task was successfully created.' }
  32.         format.json { render :show, status: :created, location: @task }
  33.       else
  34.         format.html { render :new }
  35.         format.json { render json: @task.errors, status: :unprocessable_entity }
  36.       end
  37.     end
  38.   end
  39.  
  40.   # PATCH/PUT /tasks/1
  41.   # PATCH/PUT /tasks/1.json
  42.   def update
  43.     respond_to do |format|
  44.       if @task.update(task_params)
  45.         format.html { redirect_to @task, notice: 'Task was successfully updated.' }
  46.         format.json { render :show, status: :ok, location: @task }
  47.       else
  48.         format.html { render :edit }
  49.         format.json { render json: @task.errors, status: :unprocessable_entity }
  50.       end
  51.     end
  52.   end
  53.  
  54.   # DELETE /tasks/1
  55.   # DELETE /tasks/1.json
  56.   def destroy
  57.     @task.destroy
  58.     respond_to do |format|
  59.       format.html { redirect_to tasks_url, notice: 'Task 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_task
  67.       @task = Task.find(params[:id])
  68.     end
  69.  
  70.     # Only allow a list of trusted parameters through.
  71.     def task_params
  72.       params.require(:task).permit(:name)
  73.     end
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement