Class: UserBoard
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- UserBoard
- Includes:
- EncryptableModelConcern
- Defined in:
- app/models/user_board.rb
Overview
UserBoard model, links the user and it’s boards
Class Method Summary collapse
-
.shared(is_shared) ⇒ Object
Returns user_boards where Board is
is_shared.
Instance Method Summary collapse
Methods included from EncryptableModelConcern
Class Method Details
.shared(is_shared) ⇒ Object
Returns user_boards where Board is is_shared
32 33 34 35 |
# File 'app/models/user_board.rb', line 32 def self.shared(is_shared) joins("LEFT JOIN boards ON user_boards.board_id = boards.id") .where("boards.is_shared = ?", is_shared) end |
Instance Method Details
#name ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/models/user_board.rb', line 21 def name if !@name.nil? @name else self.board.name end end |
#name=(str) ⇒ Object
17 18 19 |
# File 'app/models/user_board.rb', line 17 def name=(str) @name = str end |
#share(user_ids, new_key) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/user_board.rb', line 37 def share(user_ids, new_key) ActiveRecord::Base.transaction do user_ids.each do |usr_id| UserBoard.new({ user_id: usr_id, board_id: self.board_id, encrypted_password: nil, is_admin: false }) .save! end self.board.is_shared = true self.encrypted_password = new_key self.save! end true rescue self.errors[:base] << "Unable to share the this board" false end |