smc/grandham

View on GitHub
app/helpers/books_helper.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

module BooksHelper
  def book_cover_picture(book)
    if book.covers.empty?
      "/book_cover_missing.png"
    else
      book.covers.last.image.url(:thumb)
    end
  end

  def formatted_name(book)
    year = "(#{book.year})" if book.year.present?

    "#{book.title} #{year}"
  end

  def book_information(book, key, field)
    render partial: "books/book_information", locals: { field: field, value: book.send(key) }
  end

  def add_new_book_path
    if current_language
      new_language_book_path(current_language)
    else
      new_book_path
    end
  end
end