dev_home
cxt 5 years ago
commit c282bf6d92

@ -7,7 +7,7 @@ class LibrariesController < ApplicationController
helper_method :current_library, :library_manageable?
def index
libraries = Library.all
libraries = current_laboratory.libraries
libraries =
if User.current&.logged? && params[:type] == 'mine'

@ -16,6 +16,7 @@ class Laboratory < ApplicationRecord
has_many :courses, dependent: :destroy
has_many :competitions, dependent: :destroy
has_many :libraries, dependent: :destroy
validates :identifier, uniqueness: { case_sensitive: false }, allow_nil: true

@ -3,6 +3,7 @@ class Library < ApplicationRecord
belongs_to :user
belongs_to :cover, class_name: 'Attachment', foreign_key: :cover_id, optional: true
belongs_to :laboratory, optional: true
has_many :library_applies, dependent: :delete_all
has_many :library_library_tags, dependent: :delete_all
@ -34,6 +35,13 @@ class Library < ApplicationRecord
end
end
before_save :set_laboratory
private def set_laboratory
return unless new_record?
self.laboratory = Laboratory.current if laboratory_id.blank?
end
def increment_visited_count!(num = 1)
increment_column!(:visited_count, num)
end

@ -0,0 +1,5 @@
class AddLaboratoryIdToLibraries < ActiveRecord::Migration[5.2]
def change
add_reference :libraries, :laboratory
end
end

@ -0,0 +1,7 @@
class TransferLaboratoryData < ActiveRecord::Migration[5.2]
def change
Course.where(laboratory_id: nil).update_all(laboratory_id: 1)
Competition.where(laboratory_id: nil).update_all(laboratory_id: 1)
Library.where(laboratory_id: nil).update_all(laboratory_id: 1)
end
end
Loading…
Cancel
Save