diff --git a/app/controllers/papers_controller.rb b/app/controllers/papers_controller.rb index f4a6d37..d54b485 100644 --- a/app/controllers/papers_controller.rb +++ b/app/controllers/papers_controller.rb @@ -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 @@ -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 diff --git a/app/views/papers/edit.html.erb b/app/views/papers/edit.html.erb new file mode 100644 index 0000000..145f44b --- /dev/null +++ b/app/views/papers/edit.html.erb @@ -0,0 +1,40 @@ +

Editing paper

+ +<%= form_for :paper, url: paper_path(@paper), method: :patch do |f| %> + + <% if @paper.errors.any? %> +
+

+ <%= pluralize(@paper.errors.count, 'error') %> prohibited + this paper from being saved: +

+ +
+ <% end %> + +

+ <%= f.label :title %>
+ <%= f.text_field :title %> +

+ +

+ <%= f.label :venue %>
+ <%= f.text_field :venue %> +

+ +

+ <%= f.label :year %>
+ <%= f.text_field :year %> +

+ +

+ <%= f.submit %> +

+ +<% end %> + +<%= link_to 'Back', papers_path %> \ No newline at end of file diff --git a/app/views/papers/index.html.erb b/app/views/papers/index.html.erb index ae2c28a..01ee970 100644 --- a/app/views/papers/index.html.erb +++ b/app/views/papers/index.html.erb @@ -9,6 +9,7 @@ Venue Year Show + Edit <% @papers.each do |paper| %> @@ -17,6 +18,7 @@ <%= paper.venue %> <%= paper.year %> <%= link_to 'Show', paper %> + <%= link_to 'Edit', edit_paper_path(paper) %> <% end %> \ No newline at end of file diff --git a/spec/features/paper/edit_paper_spec.rb b/spec/features/paper/edit_paper_spec.rb index fdb3a9d..5c2401c 100644 --- a/spec/features/paper/edit_paper_spec.rb +++ b/spec/features/paper/edit_paper_spec.rb @@ -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