Sha256: 2cfbd77bc0d715e909ffa6837dd10e420c366aae250ececc724fa4aff4ab2315

Contents?: true

Size: 801 Bytes

Versions: 1

Compression:

Stored size: 801 Bytes

Contents

module Form
  class Row < ActiveRecord::Base
    include Form
    include Admin::Form::Row

    self.table_name_prefix = 'form_'

    belongs_to :structure
    has_many :fields, through: :structure
    has_one :viewable, through: :structure, class_name: 'Viewable::Form'

    validates :structure, presence: true

    delegate :with_email?, :send_to, :subject, :body, :email_column_key, :header, to: :structure
    delegate :form_name, to: :viewable

    def send_from
      send(email_column_key) if email_column_key
    end

    def labelled_values
      columns = fields.count.times.map{ |i| "column_#{i}" }
      values = header.attributes.slice(*columns)
      values.reduce({}) do |values, (column_key, label)|
        values[label] = send(column_key)
        values
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_admin_cms-0.0.1 app/models/form/row.rb