Skip to content

Instantly share code, notes, and snippets.

@jathayde
Created March 27, 2020 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jathayde/8d06b1c641ffd203afae0576aebd8abc to your computer and use it in GitHub Desktop.
Save jathayde/8d06b1c641ffd203afae0576aebd8abc to your computer and use it in GitHub Desktop.
module Attributable
extend ActiveSupport::Concern
included do
has_many :attributions, as: :attributable
has_many :sources, through: :attributions
end
end
# == Schema Information
#
# Table name: attributions
#
# id :bigint(8) not null, primary key
# attributable_type :string
# attributable_id :integer
# source_id :integer
# user_id :integer
# retrieved_on :date
# source_text :text
# description :text
# cross_issue :boolean
# cross_issue_description :text
# created_at :datetime not null
# updated_at :datetime not null
#
class Attribution < ApplicationRecord
belongs_to :source
belongs_to :attributable, polymorphic: true
accepts_nested_attributes_for :source, reject_if: :all_blank, allow_destroy: true
validates :source_id, presence: true
end
# == Schema Information
#
# Table name: sources
#
# id :bigint(8) not null, primary key
# name :string
# source_type :string
# url :text
# published_on :date
# marketable :boolean
# marketable_url :text
# marketable_details :text
# created_at :datetime not null
# updated_at :datetime not null
# source_text :text
# authors :text
# catalog_number :string
#
class Source < ApplicationRecord
has_many :attributions
validates :name,
presence: true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment