Commit d40d0704266e7e5ccba2837f5a04334c8b4b3889
Committed by
Guilherme Rojas
1 parent
9e0ca98a
Exists in
colab
and in
4 other branches
Edit action for project
Pending tests
Showing
5 changed files
with
27 additions
and
2 deletions
Show diff stats
app/controllers/projects_controller.rb
@@ -32,6 +32,21 @@ class ProjectsController < ApplicationController | @@ -32,6 +32,21 @@ class ProjectsController < ApplicationController | ||
32 | def show | 32 | def show |
33 | set_project | 33 | set_project |
34 | end | 34 | end |
35 | + | ||
36 | + # GET /projects/1/edit | ||
37 | + # GET /projects/1/edit.json | ||
38 | + def edit | ||
39 | + set_project | ||
40 | + end | ||
41 | + | ||
42 | + def update | ||
43 | + set_project | ||
44 | + if @project.update(params[:project]) | ||
45 | + redirect_to(project_path(@project.id)) | ||
46 | + else | ||
47 | + render "edit" | ||
48 | + end | ||
49 | + end | ||
35 | 50 | ||
36 | private | 51 | private |
37 | # Use callbacks to share common setup or constraints between actions. | 52 | # Use callbacks to share common setup or constraints between actions. |
app/models/project.rb
@@ -5,7 +5,12 @@ class Project < KalibroEntities::Entities::Project | @@ -5,7 +5,12 @@ class Project < KalibroEntities::Entities::Project | ||
5 | delegate :url_helpers, to: 'Rails.application.routes' | 5 | delegate :url_helpers, to: 'Rails.application.routes' |
6 | 6 | ||
7 | def persisted? | 7 | def persisted? |
8 | - false | 8 | + Project.exists?(self.id) unless self.id.nil? |
9 | + end | ||
10 | + | ||
11 | + def update(attributes = {}) | ||
12 | + attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) } | ||
13 | + self.save | ||
9 | end | 14 | end |
10 | 15 | ||
11 | def self.latest(count = 1) | 16 | def self.latest(count = 1) |
app/views/projects/_form.html.erb
app/views/projects/index.html.erb
@@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
15 | <td><%= project.name %></td> | 15 | <td><%= project.name %></td> |
16 | <td><%= project.description %></td> | 16 | <td><%= project.description %></td> |
17 | <td><%= link_to 'Show', project_path(project.id) %></td> | 17 | <td><%= link_to 'Show', project_path(project.id) %></td> |
18 | + <td><%= link_to 'Edit', edit_project_path(project.id) %></td> | ||
18 | </tr> | 19 | </tr> |
19 | <% end %> | 20 | <% end %> |
20 | </tbody> | 21 | </tbody> |