Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # == Schema Information
- #
- # Table name: books
- #
- # id :bigint not null, primary key
- # title :string
- # release_year :integer
- # created_at :datetime not null
- # updated_at :datetime not null
- #
- class Book < ApplicationRecord
- include Hashid::Rails
- attr_accessor :book_authors_attributes
- has_many :chapters, dependent: :destroy
- has_many :book_authors, dependent: :destroy
- validates :title, presence: true
- accepts_nested_attributes_for :book_authors, allow_destroy: true
- # Outputs a formatted list of the book's authors
- def author_str
- authors = ""
- book_authors.each do |author|
- authors << "#{author.author_name}, "
- end
- authors.delete_suffix(', ')
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement