mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-18 07:01:58 +08:00
15 lines
328 B
Ruby
15 lines
328 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
module ViewableModel
|
||
|
extend ActiveSupport::Concern
|
||
|
|
||
|
included do
|
||
|
has_many :view_states, as: :viewable, dependent: :destroy
|
||
|
end
|
||
|
|
||
|
def current_view_state(user)
|
||
|
state = view_states.where(user: user).take
|
||
|
state || view_states.create!(user: user, state: default_view_state)
|
||
|
end
|
||
|
end
|