Guest User

Untitled

a guest
Jun 17th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. class Artist < ApplicationRecord
  2. has_one :board, as: :boardable, dependent: :destroy
  3.  
  4. after_create -> (artist) { BoardGenerator.create(artist) }
  5. after_update -> (artist) { BoardGenerator.update(artist) }
  6. end
  7.  
  8. class Album < ApplicationRecord
  9. has_one :board, as: :boardable, dependent: :destroy
  10.  
  11. after_create -> (album) { BoardGenerator.create(album) }
  12. after_update -> (album) { BoardGenerator.update(album) }
  13. end
  14.  
  15. class Board < ApplicationRecord
  16. belongs_to :boardable, polymorphic: true, optional: true
  17. end
  18.  
  19. class BoardGenerator
  20. def self.create(boardable)
  21. boardable.board = Board.create(name: boardable.name)
  22. end
  23.  
  24. def self.update(boardable)
  25. boardable.board.update_attribute(:name, boardable.name)
  26. end
  27. end
Add Comment
Please, Sign In to add comment