Sha256: 2df0bc8539eeaa978be9f504fb3eb1df08677a2ad41a79d4ac5db48dabe76e58

Contents?: true

Size: 852 Bytes

Versions: 6

Compression:

Stored size: 852 Bytes

Contents

module Form
  extend ActiveSupport::Concern

  included do
    attr_accessor :_subtitle

    validates :_subtitle, invisible_captcha: true

    before_save :set_locale
    after_save  :send_email, if: :with_email?

    delegate :virtual?, :has_attachments?, :has_collections?, to: :class
  end

  class_methods do
    def virtual?
      false
    end

    def has_attachments?
      respond_to? :attachments
    end

    def has_collections?
      respond_to? :collections
    end

    def has_collections(*collections)
      define_singleton_method :collections do
        collections
      end

      delegate :collections, to: :class
    end
  end

  private

  def set_locale
    if has_attribute?(:locale) && locale.nil?
      self.locale = I18n.locale
    end
  end

  def send_email
    CMS::FormsMailer.send_email(self).deliver_later
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rails_admin_cms-0.0.9 app/models/form.rb
rails_admin_cms-0.0.7 app/models/form.rb
rails_admin_cms-0.0.6 app/models/form.rb
rails_admin_cms-0.0.5 app/models/form.rb
rails_admin_cms-0.0.4 app/models/form.rb
rails_admin_cms-0.0.3 app/models/form.rb