Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Artist < ApplicationRecord
- has_one :board, as: :boardable, dependent: :destroy
- after_create -> (artist) { BoardGenerator.create(artist) }
- after_update -> (artist) { BoardGenerator.update(artist) }
- end
- class Album < ApplicationRecord
- has_one :board, as: :boardable, dependent: :destroy
- after_create -> (album) { BoardGenerator.create(album) }
- after_update -> (album) { BoardGenerator.update(album) }
- end
- class Board < ApplicationRecord
- belongs_to :boardable, polymorphic: true, optional: true
- end
- class BoardGenerator
- def self.create(boardable)
- boardable.board = Board.create(name: boardable.name)
- end
- def self.update(boardable)
- boardable.board.update_attribute(:name, boardable.name)
- end
- end
Add Comment
Please, Sign In to add comment