Skip to content

Commit

Permalink
Refs #20: Add save paper input to db
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus-Brand committed Nov 3, 2017
1 parent 5cb7f0f commit ce102e3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
20 changes: 19 additions & 1 deletion app/controllers/papers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
class PapersController < ApplicationController
def new
#@paper = Paper.new()
@paper = Paper.new
end

def create
@paper = Paper.new(paper_params)
if @paper.save
redirect_to @paper
else
render 'new'
end
end

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

private
def paper_params
params.require(:paper).permit(:title, :venue, :year)
end
end
14 changes: 14 additions & 0 deletions app/views/papers/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
<h1>New paper</h1>
<%= form_for :paper, url: papers_path do |f| %>

<% if @paper.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(@paper.errors.count, "error") %>
prohibits the author to be created
</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 %>
Expand Down
14 changes: 14 additions & 0 deletions app/views/papers/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p>
<strong>Title:</strong>
<%= @paper.title %>
</p>

<p>
<strong>Venue:</strong>
<%= @paper.venue %>
</p>

<p>
<strong>Year:</strong>
<%= @paper.year %>
</p>
4 changes: 2 additions & 2 deletions spec/features/paper/new_paper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
fill_in 'paper_venue', with: 'Mind 49: 433-460'
fill_in 'paper_year', with: '1950'

expect(Paper.find_by_first_name('COMPUTING MACHINERY AND INTELLIGENCE')).to be_nil
expect(Paper.find_by_title('COMPUTING MACHINERY AND INTELLIGENCE')).to be_nil

find('input[type="submit"]').click

expect(Paper.find_by_first_name('COMPUTING MACHINERY AND INTELLIGENCE')).not_to be_nil
expect(Paper.find_by_title('COMPUTING MACHINERY AND INTELLIGENCE')).not_to be_nil
end
end

0 comments on commit ce102e3

Please sign in to comment.