bouquins-ror/app/controllers/books_controller.rb

36 lines
649 B
Ruby
Raw Normal View History

2015-06-28 12:29:09 +00:00
class BooksController < ApplicationController
include PreferencesHelper
include ERB::Util
before_action :preferences, only: :index
2015-06-28 12:29:09 +00:00
def show
@book = Book.find(params[:id])
2015-06-28 13:03:30 +00:00
@title = @book.title
end
def index
2015-08-04 11:47:26 +00:00
@books = Book.where(query_filter).order(sort_col)
.paginate(page: params[:page], per_page: @preference.per_page)
2015-06-28 13:03:30 +00:00
@title = "Books"
2015-06-29 16:58:02 +00:00
respond_to do |format|
format.html
format.js
end
2015-06-28 12:29:09 +00:00
end
def cover
@book = Book.find(params[:id])
redirect_to "/calibre/#{url_encode(@book.path)}/cover.jpg"
end
2015-08-02 09:12:04 +00:00
private
def sort_col
2015-08-04 11:47:26 +00:00
if @preference.sort == "latest"
2015-08-02 09:12:04 +00:00
return { last_modified: :desc }
end
:sort
end
2015-06-28 12:29:09 +00:00
end