bouquins-ror/app/controllers/authors_controller.rb

60 lines
1.2 KiB
Ruby
Raw Normal View History

2015-06-28 15:14:47 +00:00
class AuthorsController < ApplicationController
include PreferencesHelper
before_action :preferences, only: :index
2015-06-28 15:14:47 +00:00
def show
@author = Author.find(params[:id])
@title = @author.name
2015-07-05 18:31:36 +00:00
@tabs = [
{ action: :titles, label: "Titles", active: true, icon: "book" },
{ action: :series, label: "Series", active: false, icon: "list" },
{ action: :authors, label: "Co-Authors", active: false, icon: "user" },
]
# active tab
titles
2015-06-28 15:14:47 +00:00
end
def index
2015-08-04 11:47:26 +00:00
@authors = Author.where(query_filter).order(:sort)
.paginate(page: params[:page], per_page: @preference.per_page)
2015-06-28 15:14:47 +00:00
@title = "Authors"
2015-06-29 16:58:02 +00:00
respond_to do |format|
format.html
format.js
end
2015-06-28 15:14:47 +00:00
end
2015-07-05 18:31:36 +00:00
def titles
@author = Author.find(params[:id])
@books = @author.books.sort{|b1,b2|b1.sort <=> b2.sort}
respond_to do |format|
format.html
format.js
end
end
def series
@author = Author.find(params[:id])
respond_to do |format|
format.html
format.js
end
end
def authors
@author = Author.find(params[:id])
@authors = Array.new
@author.books.each do |b|
@authors.concat b.authors
end
@authors.uniq!
@authors.select! {|a| a != @author}
respond_to do |format|
format.html
format.js
end
end
2015-06-28 15:14:47 +00:00
end