Sebastien Lachance

Rails model without ActiveRecord

Common scenario for a contact form.

Here is how I do it:

Model without ActiveRecord in Rails
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Contact
  include ActiveModel::Validations
  include ActiveModel::Conversion

  def initialize(attributes = {})
    attributes.each do |name, value|
      send("#{name}=", value)
    end
  end

  def persisted?
    false
  end

end

Comments