File tree Expand file tree Collapse file tree 6 files changed +64
-24
lines changed Expand file tree Collapse file tree 6 files changed +64
-24
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,22 @@ def show
23
23
@project = Project . find ( params [ :id ] )
24
24
end
25
25
26
+ def edit
27
+ @project = Project . find ( params [ :id ] )
28
+ end
29
+
30
+ def update
31
+ @project = Project . find ( params [ :id ] )
32
+
33
+ if @project . update ( project_params )
34
+ flash [ :notice ] = "Project has been updated."
35
+ redirect_to @project
36
+ else
37
+ flash [ :alert ] = "Project has not been updated."
38
+ render "edit"
39
+ end
40
+ end
41
+
26
42
private
27
43
28
44
def project_params
Original file line number Diff line number Diff line change
1
+ <%= form_for(@project) do |f| %>
2
+ <% if @project.errors.any? %>
3
+ <div id ="error_explanation ">
4
+ < h2 > <%= pluralize ( @project . errors . count , "error" ) %>
5
+ prohibited this project from being saved:</ h2 >
6
+
7
+ < ul >
8
+ <% @project . errors . full_messages . each do |msg | %>
9
+ < li > <%= msg %> </ li >
10
+ <% end %>
11
+ </ ul >
12
+ </ div >
13
+ <% end %>
14
+ < p >
15
+ <%= f . label :name %> < br >
16
+ <%= f . text_field :name %>
17
+ </ p >
18
+
19
+ < p >
20
+ <%= f . label :description %> < br >
21
+ <%= f . text_field :description %>
22
+ </ p >
23
+
24
+ <%= f . submit %>
25
+ <% end %>
Original file line number Diff line number Diff line change
1
+ < h2 > Edit project</ h2 >
2
+
3
+ <%= render "form" %>
Original file line number Diff line number Diff line change 1
1
< h2 > New Project</ h2 >
2
- <%= form_for ( @project ) do |f | %>
3
- <% if @project . errors . any? %>
4
- < div id ="error_explanation ">
5
- < h2 > <%= pluralize ( @project . errors . count , "error" ) %>
6
- prohibited this project from being saved:</ h2 >
7
2
8
- < ul >
9
- <% @project . errors . full_messages . each do |msg | %>
10
- < li > <%= msg %> </ li >
11
- <% end %>
12
- </ ul >
13
- </ div >
14
- <% end %>
15
- < p >
16
- <%= f . label :name %> < br >
17
- <%= f . text_field :name %>
18
- </ p >
19
-
20
- < p >
21
- <%= f . label :description %> < br >
22
- <%= f . text_field :description %>
23
- </ p >
24
-
25
- <%= f . submit %>
26
- <% end %>
3
+ <%= render "form" %>
Original file line number Diff line number Diff line change 1
1
<% title(@project.name, "Projects") %>
2
2
<h2 > <%= @project . name %> </ h2 >
3
+ <%= link_to "Edit Project" , edit_project_path ( @project ) %>
Original file line number Diff line number Diff line change
1
+ require "rails_helper"
2
+
3
+ feature "Editing Projects" do
4
+ before do
5
+ FactoryGirl . create ( :project , name : "Sublime Text 3" )
6
+
7
+ visit "/"
8
+ click_link "Sublime Text 3"
9
+ click_link "Edit Project"
10
+ end
11
+
12
+ scenario "Updating a project" do
13
+ fill_in "Name" , with : "Sublime Text 3 beta"
14
+ click_button "Update Project"
15
+
16
+ expect ( page ) . to have_content ( "Project has been updated." )
17
+ end
18
+ end
You can’t perform that action at this time.
0 commit comments