forked from hpi-swt2-exercise/rails-exercise-16
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
636 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Place all the behaviors and hooks related to the matching controller here. | ||
// All this logic will automatically be available in application.js. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Place all the behaviors and hooks related to the matching controller here. | ||
// All this logic will automatically be available in application.js. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* | ||
Place all the styles related to the matching controller here. | ||
They will automatically be included in application.css. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* | ||
Place all the styles related to the matching controller here. | ||
They will automatically be included in application.css. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
body { | ||
background-color: #fff; | ||
color: #333; | ||
margin: 33px; | ||
} | ||
|
||
body, p, ol, ul, td { | ||
font-family: verdana, arial, helvetica, sans-serif; | ||
font-size: 13px; | ||
line-height: 18px; | ||
} | ||
|
||
pre { | ||
background-color: #eee; | ||
padding: 10px; | ||
font-size: 11px; | ||
} | ||
|
||
a { | ||
color: #000; | ||
} | ||
|
||
a:visited { | ||
color: #666; | ||
} | ||
|
||
a:hover { | ||
color: #fff; | ||
background-color: #000; | ||
} | ||
|
||
th { | ||
padding-bottom: 5px; | ||
} | ||
|
||
td { | ||
padding: 0 5px 7px; | ||
} | ||
|
||
div.field, | ||
div.actions { | ||
margin-bottom: 10px; | ||
} | ||
|
||
#notice { | ||
color: green; | ||
} | ||
|
||
.field_with_errors { | ||
padding: 2px; | ||
background-color: red; | ||
display: table; | ||
} | ||
|
||
#error_explanation { | ||
width: 450px; | ||
border: 2px solid red; | ||
padding: 7px 7px 0; | ||
margin-bottom: 20px; | ||
background-color: #f0f0f0; | ||
} | ||
|
||
#error_explanation h2 { | ||
text-align: left; | ||
font-weight: bold; | ||
padding: 5px 5px 5px 15px; | ||
font-size: 12px; | ||
margin: -7px -7px 0; | ||
background-color: #c00; | ||
color: #fff; | ||
} | ||
|
||
#error_explanation ul li { | ||
font-size: 12px; | ||
list-style: square; | ||
} | ||
|
||
label { | ||
display: block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# A frequent practice is to place the standard CRUD actions in each controller in the following order: | ||
# index, show, new, edit, create, update and destroy. | ||
# You may use any order you choose, but keep in mind that these are public methods; | ||
# they must be placed before declaring private visibility in the controller. | ||
|
||
class AuthorsController < ApplicationController | ||
def index | ||
@authors = Author.all | ||
end | ||
|
||
def show | ||
@author = Author.find(params[:id]) | ||
end | ||
|
||
def new | ||
@author = Author.new | ||
end | ||
|
||
def edit | ||
@author = Author.find(params[:id]) | ||
end | ||
|
||
def create | ||
@author = Author.new(author_params) | ||
|
||
if @author.save | ||
redirect_to @author | ||
else | ||
render 'new' | ||
end | ||
end | ||
|
||
def update | ||
@author = Author.find(params[:id]) | ||
|
||
if @author.update(author_params) | ||
redirect_to @author | ||
else | ||
render 'edit' | ||
end | ||
end | ||
|
||
def destroy | ||
@author = Author.find(params[:id]) | ||
@author.destroy | ||
|
||
redirect_to authors_path | ||
end | ||
|
||
private | ||
def author_params | ||
params.require(:author).permit(:first_name, :last_name, :homepage) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
class PapersController < ApplicationController | ||
before_action :set_paper, only: [:show, :edit, :update, :destroy] | ||
|
||
# GET /papers | ||
def index | ||
@papers = Paper.all | ||
@papers = @papers.published_in params[:year] if params[:year] | ||
end | ||
|
||
# GET /papers/1 | ||
def show | ||
end | ||
|
||
# GET /papers/new | ||
def new | ||
@paper = Paper.new | ||
end | ||
|
||
# GET /papers/1/edit | ||
def edit | ||
end | ||
|
||
# POST /papers | ||
def create | ||
@paper = Paper.new(paper_params) | ||
|
||
if @paper.save | ||
redirect_to @paper, notice: 'Paper was successfully created.' | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
# PATCH/PUT /papers/1 | ||
def update | ||
if @paper.update(paper_params) | ||
redirect_to @paper, notice: 'Paper was successfully updated.' | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
# DELETE /papers/1 | ||
def destroy | ||
@paper.destroy | ||
redirect_to papers_url, notice: 'Paper was successfully destroyed.' | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_paper | ||
@paper = Paper.find(params[:id]) | ||
end | ||
|
||
# Only allow a trusted parameter "white list" through. | ||
def paper_params | ||
params.require(:paper).permit(:title, :venue, :year, :author_ids => []) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module AuthorsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module PapersHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Author < ApplicationRecord | ||
#Validations | ||
#validates :last_name, presence: true | ||
|
||
# Relations | ||
has_and_belongs_to_many :papers | ||
|
||
def name | ||
"#{self.first_name} #{self.last_name}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Paper < ApplicationRecord | ||
#Scopes | ||
scope :published_in, ->(year) { where("year == ?", year)} | ||
|
||
#Validations | ||
#validates :title, presence: true | ||
#validates :venue, presence: true | ||
#validates :year, numericality: true, presence: true | ||
|
||
# Relations | ||
has_and_belongs_to_many :authors | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<h1>Edit author</h1> | ||
|
||
<%= form_with(model: @author, local: true) do |form| %> | ||
|
||
<% if @author.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@author.errors.count, "error") %> prohibited this author from being saved:</h2> | ||
<ul> | ||
<% @author.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<% [:first_name, :last_name, :homepage].each do |attribute| %> | ||
<p> | ||
<strong><%= Author.human_attribute_name(attribute) %>:</strong> | ||
<br> | ||
<%= form.text_field attribute %> | ||
</p> | ||
<% end %> | ||
|
||
<p><%= form.submit %></p> | ||
|
||
<% end %> | ||
|
||
<%= link_to 'Back to author index', authors_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<h1>Author Index</h1> | ||
|
||
<style> | ||
table, th, td { | ||
border: 1px solid black; | ||
border-collapse: collapse; | ||
} | ||
</style> | ||
|
||
<table> | ||
<tr> | ||
<th>full_name</th> | ||
<th>homepage</th> | ||
<th></th> | ||
</tr> | ||
|
||
<% @authors.each do |author| %> | ||
<tr> | ||
<td><%= author.name %></td> | ||
<td><%= author.homepage %></td> | ||
<td><%= link_to 'Show', author_path(author) %> | ||
<%= link_to 'Edit', edit_author_path(author) %> | ||
<%= link_to 'Delete', author_path(author), method: :delete, data: { confirm: 'Are you sure?' } %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<p> | ||
<%= link_to 'Add new author', new_author_path %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<h1>New Author</h1> | ||
|
||
<%= form_with scope: :author, url: authors_path, local: true do |form| %> | ||
<%# Show validation errors%> | ||
<% if @author.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@author.errors.count, "error") %> prohibited this article from being saved:</h2> | ||
<ul> | ||
<% @author.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<% [:first_name, :last_name, :homepage].each do |attr| %> | ||
<p> | ||
<%= form.label attr %><br> | ||
<%= form.text_field attr %> | ||
</p> | ||
<% end %> | ||
|
||
<p> | ||
<%= form.submit %> | ||
</p> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<h1>Author Details: <%= @author.name %></h1> | ||
|
||
<% [:first_name, :last_name, :homepage].each do |attribute| %> | ||
<p> | ||
<strong><%= Author.human_attribute_name(attribute) %>:</strong> | ||
<br> | ||
<%= @author.send(attribute) %> | ||
</p> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<h1>views/home/index.html.erb</h1> | ||
<h1>A System</h1> | ||
<%# link_to 'authors', authors_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<%= form_with(model: paper, local: true) do |form| %> | ||
<% 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 |message| %> | ||
<li><%= message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<%= form.label :title %> | ||
<%= form.text_field :title %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :venue %> | ||
<%= form.text_field :venue %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :year %> | ||
<%= form.number_field :year %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label 'Authors' %> | ||
<%= form.select 'author_ids', | ||
options_from_collection_for_select(Author.all, :id, :name, paper.author_ids), | ||
{}, | ||
multiple: true, size: 10 %> | ||
</div> | ||
|
||
<div class="actions"> | ||
<%= form.submit %> | ||
</div> | ||
|
||
|
||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Editing Paper</h1> | ||
|
||
<%= render 'form', paper: @paper %> | ||
|
||
<%= link_to 'Show', @paper %> | | ||
<%= link_to 'Back', papers_path %> |
Oops, something went wrong.