bouquins-ror/app/controllers/books_controller.rb

42 lines
783 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-03 11:14:56 +00:00
filters = initial_filter
if params[:s]
filters[0] << " AND sort like ?"
filters.push("%#{params[:s]}%")
end
puts filters
@books = Book.where(filters).order(sort_col)
.paginate(page: params[:page], per_page: session[:current_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
if session[:sort] == "latest"
return { last_modified: :desc }
end
:sort
end
2015-06-28 12:29:09 +00:00
end