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 | 32 | def show |
33 | 33 | set_project |
34 | 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 | 51 | private |
37 | 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 | 5 | delegate :url_helpers, to: 'Rails.application.routes' |
6 | 6 | |
7 | 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 | 14 | end |
10 | 15 | |
11 | 16 | def self.latest(count = 1) | ... | ... |
app/views/projects/_form.html.erb
app/views/projects/index.html.erb