1
+ # frozen_string_literal: true
2
+
1
3
class BooksController < ApplicationController
2
4
before_filter :book_resource , only : [ :section , :chapter ]
3
5
4
6
def show
5
7
lang = params [ :lang ] || "en"
6
8
if edition = params [ :edition ]
7
- @book = Book . where ( : code => lang , : edition => edition ) . first
9
+ @book = Book . where ( code : lang , edition : edition ) . first
8
10
else
9
- @book = Book . where ( : code => lang ) . order ( "percent_complete DESC, edition DESC" ) . first
11
+ @book = Book . where ( code : lang ) . order ( "percent_complete DESC, edition DESC" ) . first
10
12
raise PageNotFound unless @book
11
13
redirect_to "/book/#{ lang } /v#{ @book . edition } "
12
14
end
@@ -15,18 +17,18 @@ def show
15
17
16
18
def link
17
19
link = params [ :link ]
18
- @book = Book . where ( : code => params [ :lang ] , : edition => params [ :edition ] ) . first
20
+ @book = Book . where ( code : params [ :lang ] , edition : params [ :edition ] ) . first
19
21
raise PageNotFound unless @book
20
- xref = @book . xrefs . where ( : name => link ) . first
22
+ xref = @book . xrefs . where ( name : link ) . first
21
23
raise PageNotFound unless xref
22
24
return redirect_to "/book/#{ @book . code } /v#{ @book . edition } /#{ ERB ::Util . url_encode ( xref . section . slug ) } ##{ xref . name } " unless @content
23
25
end
24
26
25
27
def section
26
- @content = @book . sections . where ( : slug => params [ :slug ] ) . first
28
+ @content = @book . sections . where ( slug : params [ :slug ] ) . first
27
29
if !@content
28
- @book = Book . where ( : code => @book . code , : edition => 1 ) . first
29
- if @content = @book . sections . where ( : slug => params [ :slug ] ) . first
30
+ @book = Book . where ( code : @book . code , edition : 1 ) . first
31
+ if @content = @book . sections . where ( slug : params [ :slug ] ) . first
30
32
return redirect_to "/book/#{ @book . code } /v#{ @book . edition } /#{ params [ :slug ] } "
31
33
else
32
34
return redirect_to "/book/#{ @book . code } "
@@ -45,18 +47,18 @@ def chapter
45
47
chapter = params [ :chapter ] . to_i
46
48
section = params [ :section ] . to_i
47
49
lang = params [ :lang ] || "en"
48
- chapter = @book . chapters . where ( : number => chapter ) . first
49
- @content = chapter . sections . where ( : number => section ) . first
50
+ chapter = @book . chapters . where ( number : chapter ) . first
51
+ @content = chapter . sections . where ( number : section ) . first
50
52
raise PageNotFound unless @content
51
53
return redirect_to "/book/#{ lang } /v2/#{ @content . slug } "
52
54
end
53
55
54
56
def book_resource
55
57
if edition = params [ :edition ]
56
- @book ||= Book . where ( : code => ( params [ :lang ] || "en" ) , : edition => edition ) . first
58
+ @book ||= Book . where ( code : ( params [ :lang ] || "en" ) , edition : edition ) . first
57
59
else
58
60
@no_edition = true
59
- @book ||= Book . where ( : code => ( params [ :lang ] || "en" ) ) . order ( "percent_complete DESC, edition DESC" ) . first
61
+ @book ||= Book . where ( code : ( params [ :lang ] || "en" ) ) . order ( "percent_complete DESC, edition DESC" ) . first
60
62
end
61
63
raise PageNotFound unless @book
62
64
@book
0 commit comments