Skip to content

Commit

Permalink
Refs #23: Paper to DB
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBrendel committed Nov 3, 2017
1 parent 48c9e89 commit 725a53c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
21 changes: 20 additions & 1 deletion app/controllers/papers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
class PapersController < ApplicationController
def new
#@paper = Paper.new
@paper = Paper.new
end

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

def create
@paper = Paper.new(paper_params)

if @paper.save
redirect_to @paper
else
render 'new'
end
end
end

private
def paper_params
params.require(:paper).permit(:title, :venue, :year)
end
14 changes: 14 additions & 0 deletions app/views/papers/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<%= form_for :paper, url: papers_path 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 %>
Expand Down
10 changes: 10 additions & 0 deletions app/views/papers/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h1>PAPER</h1>

<p>
<strong>Title:</strong>
<%= @paper.title %>
<strong>Venue:</strong>
<%= @paper.venue %>
<strong>Year:</strong>
<%= @paper.year %>
</p>

0 comments on commit 725a53c

Please sign in to comment.