Skip to content

Commit

Permalink
Refs #32: filter papers by year
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBrendel committed Nov 4, 2017
1 parent eb0376c commit ae359e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/controllers/papers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
class PapersController < ApplicationController
def index
@papers = Paper.all
year = params[:year]
if year
@papers = Paper.created_in year
else
@papers = Paper.all
end
end

def new
Expand Down
1 change: 1 addition & 0 deletions app/models/paper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Paper < ActiveRecord::Base
scope :created_in, ->(year) { where('year == ?', year) }
validates :title, :venue, :year, presence: true
validates :year, numericality: { only_integer: true }
has_and_belongs_to_many :authors
Expand Down

0 comments on commit ae359e1

Please sign in to comment.