title: Rails validation from controller
body: <p>There is a contact page, which offers to enter name, telephone, email and message, after that it sends to an administrator's email. There is no reason to store message in DB.</p>
  
  <p>Question. How to:</p>
  
  <ol>
  <li><p>Use Rails validations in controller, not using model at all, OR</p></li>
  <li><p>Use validations in model, but without any DB relations</p></li>
  </ol>
  
  <p><strong>UPD:</strong></p>
  
  <p>Model:</p>
  
  <pre><code>class ContactPageMessage
  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming
  
  attr_accessor :name, :telephone, :email, :message
  validates :name, :telephone, :email, :message, presence: true
  validates :email, email_format: { :message =&gt; "Неверный формат E-mail адреса"}
  
  def initialize(attributes = {})
      attributes.each do |name, value|
        send("#{name}=", value)
      end
  end
  
  def persisted?
    false
  end
  end
  </code></pre>
  
  <p>controller:</p>
  
  <pre><code>def sendmessage
  cpm = ContactPageMessage.new()
  if cpm.valid?
      @settings = Setting.first
      if !@settings
          redirect_to contacts_path, :alert =&gt; "Fail"
      end
      if ContactPageMessage.received(params).deliver
          redirect_to contacts_path, :notice =&gt; "Success"
      else
          redirect_to contacts_path, :alert =&gt; "Fail"
      end
  else
      redirect_to contacts_path, :alert =&gt; "Fail"
  end
  end
  end
  </code></pre>