Last active
August 29, 2015 14:17
-
-
Save firedev/be2cac112f314ab91903 to your computer and use it in GitHub Desktop.
Blocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Page | |
has_many :blocks, -> { ordered }, dependent: :destroy | |
attr_accessors :title | |
def visible_blocks | |
@visible_block ||= blocks.current_locale.map(&:blockable) | |
end | |
end | |
class Block | |
belongs_to :page | |
belongs_to :blockable, polymorphic: true, dependent: :destroy | |
attr_accessor :locale | |
scope :ordered, -> { order position: :desc } | |
scope :current_locale, -> { where('(locale = ? OR locale IS NULL)') } | |
end | |
module Blockable | |
extend ActiveSupport::Concern | |
included do | |
has_one :block, as: :blockable, dependent: :destroy | |
end | |
end | |
class TextBlock | |
include Blockable | |
attr_accessor :body | |
end | |
class DownloadBlock | |
include Blockable | |
has_many :attachments | |
end | |
class ImageBlock | |
include Blockable | |
has_many :images | |
end | |
class MapBlock | |
include Blockable | |
attr_accessor :latitude, :longitude, :zoom | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment