Guest User

Untitled

a guest
Jul 16th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. class TasksController < ApplicationController
  2. # GET /tasks
  3. # GET /tasks.xml
  4. def index
  5. @tasks = Task.all
  6.  
  7. respond_to do |format|
  8. format.html # index.html.erb
  9. format.xml { render :xml => @tasks }
  10. end
  11. end
  12.  
  13. # GET /tasks/1
  14. # GET /tasks/1.xml
  15. def show
  16. @task = Task.find(params[:id])
  17.  
  18. respond_to do |format|
  19. format.html # show.html.erb
  20. format.xml { render :xml => @task }
  21. end
  22. end
  23.  
  24. # GET /tasks/new
  25. # GET /tasks/new.xml
  26. def new
  27. @task = Task.new
  28.  
  29. respond_to do |format|
  30. format.html # new.html.erb
  31. format.xml { render :xml => @task }
  32. end
  33. end
  34.  
  35. # GET /tasks/1/edit
  36. def edit
  37. @task = Task.find(params[:id])
  38. end
  39.  
  40. # POST /tasks
  41. # POST /tasks.xml
  42. def create
  43. @task = Task.new(params[:task])
  44.  
  45. respond_to do |format|
  46. if @task.save
  47. flash[:notice] = 'Task was successfully created.'
  48. format.html { redirect_to(@task) }
  49. format.xml { render :xml => @task, :status => :created, :location => @task }
  50. else
  51. format.html { render :action => "new" }
  52. format.xml { render :xml => @task.errors, :status => :unprocessable_entity }
  53. end
  54. end
  55. end
  56.  
  57. # PUT /tasks/1
  58. # PUT /tasks/1.xml
  59. def update
  60. @task = Task.find(params[:id])
  61.  
  62. respond_to do |format|
  63. if @task.update_attributes(params[:task])
  64. flash[:notice] = 'Task was successfully updated.'
  65. format.html { redirect_to(@task) }
  66. format.xml { head :ok }
  67. else
  68. format.html { render :action => "edit" }
  69. format.xml { render :xml => @task.errors, :status => :unprocessable_entity }
  70. end
  71. end
  72. end
  73.  
  74. # DELETE /tasks/1
  75. # DELETE /tasks/1.xml
  76. def destroy
  77. @task = Task.find(params[:id])
  78. @task.destroy
  79.  
  80. respond_to do |format|
  81. format.html { redirect_to(tasks_url) }
  82. format.xml { head :ok }
  83. end
  84. end
  85. end
Add Comment
Please, Sign In to add comment