Sha256: 12fe2e028fc8da08721f81f4c3a9972136d72123fac43c36d6607e98d0519724

Contents?: true

Size: 566 Bytes

Versions: 5

Compression:

Stored size: 566 Bytes

Contents

# frozen_string_literal: true

module MicroCms
  class ContentBlock < ApplicationRecord
    validates :path, presence: true
    validates :content, exclusion: { in: [nil] }

    def self.table_name_prefix
      'micro_cms_'
    end

    def self.format_path(i18n_key)
      "#{i18n_key.parameterize}-#{I18n.locale}"
    end

    def self.content_block_for_path(path, content: '')
      ContentBlock.find_or_create_by(path: format_path(path)) do |content_block|
        content_block.content = content
      end
    end

    def to_param
      path
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
micro_cms-0.2.1 app/models/micro_cms/content_block.rb
micro_cms-0.2.0 app/models/micro_cms/content_block.rb
micro_cms-0.1.2 app/models/micro_cms/content_block.rb
micro_cms-0.1.1 app/models/micro_cms/content_block.rb
micro_cms-0.1.0 app/models/micro_cms/content_block.rb