Commit d40d0704266e7e5ccba2837f5a04334c8b4b3889

Authored by Guilherme Rojas V. de Lima + Rafael Reggiani Manzo
Committed by Guilherme Rojas
1 parent 9e0ca98a

Edit action for project

Pending tests
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
1   - <% #raise @project.inspect %>
2 1 <%= form_for(@project) do |f| %>
3 2 <%= render :partial => 'shared/form_errors', :locals => {:object => @project} %>
4 3  
... ...
app/views/projects/edit.html.erb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +<h1>Edit Project</h1>
  2 +
  3 +<%= render 'form' %>
  4 +
  5 +<%= link_to 'Back', projects_path %>
... ...
app/views/projects/index.html.erb
... ... @@ -15,6 +15,7 @@
15 15 <td><%= project.name %></td>
16 16 <td><%= project.description %></td>
17 17 <td><%= link_to 'Show', project_path(project.id) %></td>
  18 + <td><%= link_to 'Edit', edit_project_path(project.id) %></td>
18 19 </tr>
19 20 <% end %>
20 21 </tbody>
... ...