Sha256: 4181c605896ea723f27e6d540bb2de892ecb29161a79487e1add83e49b2c4253

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

module Georgia
	class Message < ActiveRecord::Base

    attr_accessible :name, :email, :subject, :message, :attachment, :phone
    delegate :url, :current_path, :size, :content_type, :filename, to: :attachment

    validates :name, presence: true
    validates :email, format: /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
    validates :message, presence: true

    mount_uploader :attachment, Georgia::AttachmentUploader

    # Anti Spam: check https://github.com/joshfrench/rakismet for more details
    include Rakismet::Model
    rakismet_attrs author: :name, author_email: :email, content: :message, comment_type: 'message'
    attr_accessible :user_ip, :user_agent, :referrer, :spam, :verified_at
    attr_accessor :permalink, :author_url

    scope :spam, where(spam: true)
    scope :ham, where(spam: false)
    scope :latest, order("created_at DESC")

    # Search
    searchable do
      text :name
      text :email
      text :message
      text :subject
      text :phone
      string :spam do
        status
      end
      # For sorting:
      string :name
      string :email
      string :phone
      string :subject
      string :message
      time :created_at
    end

    def status
      @status ||= spam ? 'spam' : 'clean'
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
georgia-0.7.1 app/models/georgia/message.rb
georgia-0.7.0 app/models/georgia/message.rb