Skip to content

Commit

Permalink
Refs #27: edit papers
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBrendel committed Nov 3, 2017
1 parent 907466c commit 521aa7d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
14 changes: 14 additions & 0 deletions app/controllers/papers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def new
@paper = Paper.new
end

def edit
@paper = Paper.find(params[:id])
end

def show
@paper = Paper.find(params[:id])
end
Expand All @@ -20,6 +24,16 @@ def create
render 'new'
end
end

def update
@paper = Paper.find(params[:id])

if @paper.update(paper_params)
redirect_to @paper
else
render 'edit'
end
end
end

private
Expand Down
40 changes: 40 additions & 0 deletions app/views/papers/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<h1>Editing paper</h1>

<%= form_for :paper, url: paper_path(@paper), method: :patch do |f| %>

<% if @paper.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@paper.errors.count, 'error') %> prohibited
this paper from being saved:
</h2>
<ul>
<% @paper.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

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

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

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

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

<% end %>

<%= link_to 'Back', papers_path %>
2 changes: 2 additions & 0 deletions app/views/papers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<th>Venue</th>
<th>Year</th>
<th>Show</th>
<th>Edit</th>
</tr>

<% @papers.each do |paper| %>
Expand All @@ -17,6 +18,7 @@
<td><%= paper.venue %></td>
<td><%= paper.year %></td>
<td><%= link_to 'Show', paper %></td>
<td><%= link_to 'Edit', edit_paper_path(paper) %></td>
</tr>
<% end %>
</table>
2 changes: 1 addition & 1 deletion spec/features/paper/edit_paper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
visit edit_paper_path(@test_paper)
end
it 'should edit with no error' do
@test_paper = FactoryGirl.create :author
@test_paper = FactoryGirl.create :paper
visit edit_paper_path(@test_paper)

fill_in 'paper_year', with: 12_345
Expand Down

0 comments on commit 521aa7d

Please sign in to comment.