File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,16 @@ def random
21
21
end
22
22
end
23
23
24
+ def read
25
+ @quotes = Quote . where ( id : cookies [ :quotes_read ] . split ( /,\s */ ) ) rescue [ ]
26
+ respond_to do |format |
27
+ format . text do
28
+ render text : @quotes . map ( &:as_text ) . join ( "\n " )
29
+ end
30
+ format . json { render json : @quotes }
31
+ end
32
+ end
33
+
24
34
# GET /quotes
25
35
# GET /quotes.json
26
36
def index
@@ -33,6 +43,10 @@ def index
33
43
@quotes ||= Quote . where ( language : request . env [ "HTTP_ACCEPT_LANGUAGE" ] )
34
44
end
35
45
46
+ if params [ :unread ] . present? && !cookies [ :quotes_read ] . blank?
47
+ @quotes = ( @quotes || Quote ) . where ( "id NOT IN (?)" , cookies [ :quotes_read ] . split ( /,\s */ ) )
48
+ end
49
+
36
50
@quotes ||= Quote . all
37
51
38
52
respond_to do |format |
@@ -49,6 +63,10 @@ def index
49
63
def show
50
64
@quote = Quote . find_by_id ( params [ :id ] )
51
65
66
+ quotes_read = cookies [ :quotes_read ] . split ( /,\s */ ) rescue [ ]
67
+ quotes_read << @quote . id . to_s
68
+ cookies [ :quotes_read ] = quotes_read . join ( "," )
69
+
52
70
respond_to do |format |
53
71
format . html # show.html.erb
54
72
format . json do
Original file line number Diff line number Diff line change 2
2
root :to => redirect ( '/quotes' )
3
3
resources :quotes do
4
4
get :random , on : :collection
5
+ get :read , on : :collection
5
6
end
6
7
7
8
# The priority is based upon order of creation:
You can’t perform that action at this time.
0 commit comments