Guest User

Untitled

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