personal-book/app/helpers/admin/personal_books_helper.rb

28 lines
894 B
Ruby
Raw Normal View History

2015-01-09 07:38:49 +00:00
module Admin::PersonalBooksHelper
def get_paper_list
user = current_user.nil? ? OrbitHelper.current_user : current_user
user_profile = user.member_profile
books = Book.where(:member_profile_id => user_profile.id)
books = books.collect do |b|
files = b.book_files.collect do |bf|
{
"title" => bf.title,
"description" => bf.description,
"link" => bf.member_book_file.url,
"extension" => (bf.file.url.split(".").last rescue "")
}
end
{
"id" => b.id.to_s,
"edit_url" => "/#{I18n.locale.to_s}/admin/members/#{user_profile.to_param}/books/#{b.to_param}/edit",
"delete_url" => "/#{I18n.locale.to_s}/admin/books/#{b.id.to_s}",
"paper_title" => b.book_title,
"keywords" => b.keywords,
"files" => files
}
end
books
end
end