bouquins-ror/app/controllers/authors_controller.rb

55 lines
1.4 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 17:32:38 +00:00
@authors = Author.where(query_filter)
.order(:sort)
.paginate(pagination)
2015-08-14 08:10:03 +00:00
@title = t(: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
2015-08-15 14:04:35 +00:00
@series = Serie.find_by_sql(["select distinct s.* from series s left outer join books_series_link bsl on bsl.series = s.id left outer join books_authors_link bal on bal.book = bsl.book where bal.author = ?", params[:id]])
2015-07-05 18:31:36 +00:00
respond_to do |format|
format.html
format.js
end
end
def authors
2015-08-15 13:51:02 +00:00
@authors = Author.find_by_sql(["select distinct a.* from books_authors_link bal1 left outer join books_authors_link bal2 on bal1.book = bal2.book left outer join authors a on a.id = bal2.author where bal1.author = ? and bal2. author != ?", params[:id], params[:id]])
2015-07-05 18:31:36 +00:00
respond_to do |format|
format.html
format.js
end
end
2015-06-28 15:14:47 +00:00
end