* Add index and show pages for series
* Address code review
* Use `id` instead of `slug` to get collections
* Extract `collection_link` into the application helper
* Only count published articles
* Get rid of the `collection_link_class` method
* Add tests
* Fix test
* Use `**kwargs` instead of `options = {}`
24 lines
476 B
Ruby
24 lines
476 B
Ruby
class Collection < ApplicationRecord
|
|
has_many :articles
|
|
belongs_to :user
|
|
belongs_to :organization, optional: true
|
|
|
|
validates :user_id, presence: true
|
|
validates :slug, presence: true, uniqueness: { scope: :user_id }
|
|
|
|
after_touch :touch_articles
|
|
|
|
def self.find_series(slug, user)
|
|
Collection.find_or_create_by(slug: slug, user: user)
|
|
end
|
|
|
|
def path
|
|
"/#{user.username}/series/#{id}"
|
|
end
|
|
|
|
private
|
|
|
|
def touch_articles
|
|
articles.touch_all
|
|
end
|
|
end
|