Skip to content

Commit

Permalink
added filter by year, solved #34
Browse files Browse the repository at this point in the history
  • Loading branch information
akuchinke committed Nov 9, 2017
1 parent e1d8c4b commit e9d4b62
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/controllers/papers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
class PapersController < ApplicationController
def index
@papers = Paper.all
@papers = []
if params.has_key?(:year)
@papers = Paper.matches_year(params[:year].to_i)
else
@papers = Paper.all
end

end

def show
Expand Down
4 changes: 4 additions & 0 deletions app/models/paper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ class Paper < ActiveRecord::Base
validates :title, presence: true
validates :venue, presence: true
validates :year, presence: true, numericality: { only_integer: true }

def self.matches_year(year)
return self.all.select{|p| p.year == year}
end
end

0 comments on commit e9d4b62

Please sign in to comment.