Blob of app/controllers/projects_controller.rb (raw blob data)

1 class ProjectsController < ApplicationController
2 before_filter :login_required
3
4 layout "standard"
5
6 undoable_methods
7
8 # GET /projects
9 # GET /projects.xml
10 def index
11 @projects = current_user.projects.find(:all)
12
13 respond_to do |format|
14 format.html # index.html.erb
15 format.xml { render :xml => @projects }
16 end
17 end
18
19 # GET /projects/1
20 # GET /projects/1.xml
21 def show
22 @project = current_user.projects.find(params[:id])
23
24 respond_to do |format|
25 format.html # show.html.erb
26 format.xml { render :xml => @project }
27 end
28 end
29
30 # GET /projects/new
31 # GET /projects/new.xml
32 def new
33 @project = current_user.projects.new
34
35 respond_to do |format|
36 format.html # new.html.erb
37 format.xml { render :xml => @project }
38 end
39 end
40
41 # GET /projects/1/edit
42 def edit
43 @project = current_user.projects.find(params[:id])
44 end
45
46 # POST /projects
47 # POST /projects.xml
48 def create
49 @project = current_user.projects.new(params[:project])
50
51 respond_to do |format|
52 change("create project #{@project.title}", projects_path, projects_path) do
53 if @project.save
54 flash[:notice] = 'Project was successfully created.'
55 format.html { redirect_to(@project) }
56 format.xml { render :xml => @project, :status => :created, :location => @project }
57 else
58 format.html { render :action => "new" }
59 format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
60 end
61 end
62 end
63 end
64
65 # PUT /projects/1
66 # PUT /projects/1.xml
67 def update
68 @project = current_user.projects.find(params[:id])
69
70 respond_to do |format|
71 change("update project #{@project.title}", edit_project_path(@project), project_path(@project)) do
72 if @project.update_attributes(params[:project])
73 flash[:notice] = 'Project was successfully updated.'
74 format.html { redirect_to(@project) }
75 format.xml { head :ok }
76 else
77 format.html { render :action => "edit" }
78 format.xml { render :xml => @project.errors, :status => :unprocessable_entity }
79 end
80 end
81 end
82 end
83
84 # DELETE /projects/1
85 # DELETE /projects/1.xml
86 def destroy
87 @project = current_user.projects.find(params[:id])
88 change("delete project #{@project.title}", project_path(@project), projects_path) do
89 @project.destroy
90 end
91
92 respond_to do |format|
93 format.html { redirect_to(projects_url) }
94 format.xml { head :ok }
95 end
96 end
97 end