Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

Commit

Permalink
Add project editing.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidS committed Jul 27, 2014
1 parent 349bf88 commit 6fbdd63
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
15 changes: 15 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ def show
@project = Project.find(params[:id])
end

def edit
@project = Project.find(params[:id])
end

def update
@project = Project.find(params[:id])
@project.update(project_params)

if @project.save
redirect_to projects_url
else
render :edit
end
end

def destroy
@project = Project.find(params[:id])
@project.destroy
Expand Down
26 changes: 26 additions & 0 deletions app/views/projects/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<h1>Edit Project</h1>

<%= form_for :project, url: @project, method: :put do |f| %>
<% if @project.errors.any? %>
<div class="error_messages">
<h2>Form is invalid</h2>
<ul>
<% for message in @project.errors.full_messages %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<p>
<%= f.label :name %><br>
<%= f.text_field :name %>
</p>

<p>
<%= f.submit %>
</p>

<% end %>

2 changes: 1 addition & 1 deletion app/views/projects/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<ul>
<% @projects.each do |project| %>
<li><%= link_to project.name, project %> | <%= link_to "Destroy", project, method: :delete %></li>
<li><%= link_to project.name, project %> | <%= link_to "Edit", edit_project_path(project) %> | <%= link_to "Destroy", project, method: :delete %></li>
<% end %>
</ul>

Expand Down
2 changes: 1 addition & 1 deletion app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1>Project "<%= @project.name %>"</h1>

<p>A nice project.</p>
<p>A nice project. <%= link_to "Edit it!", edit_project_path %></p>

<p><%= link_to 'All projects', projects_path %></p>

0 comments on commit 6fbdd63

Please sign in to comment.