Sha256: 7d8f51109dc79d329f90b4d3b54ad4889424c46a3af8257a0ebaf3ca9d8d25f6

Contents?: true

Size: 982 Bytes

Versions: 1

Compression:

Stored size: 982 Bytes

Contents

class Forms::Submission < Wheelhouse::BasicResource
  include Wheelhouse::Resource::AdminPath
  
  property :params, Parameters
  property :ip_address, String
  property :spam, Boolean, :default => false, :protected => true
  timestamps!
  
  belongs_to :form, :class => "Forms::Form"
  
  default_scope order(:created_at.desc)
  
  scope :spam, where(:spam => true)
  scope :not_spam, where(:spam.ne => true)
  
  validate do
    form.fields.flatten.each do |field|
      if field.required? && value_for(field).blank?
        errors.add(field.label, "This field is required")
      end
    end
  end
  
  def spam!(is_spam)
    Forms::Plugin.config.wheelhouse.forms.spam_filter.train(self, is_spam)
    update_attribute(:spam, is_spam)
  end
  
  def value_for(field)
    params[field.label] if field.respond_to?(:label)
  end
  
  def admin_path
    form_submission_path(form_id, id)
  end
  
  def admin_url
    form_submission_url(form, id, :host => form.site.domain)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wheelhouse-forms-1.1 app/models/forms/submission.rb