BasicModel is a tiny Module that complies with the ActiveModel API
Ruby Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
gemfiles
lib
test
.gitignore
.travis.yml
Gemfile
LICENSE
README.md
Rakefile
basic_model.gemspec

README.md

BasicModel

BasicModel is intended to be used in a tableless model in Rails >= 3.0. It complies with the ActiveModel API and includes validations, so it can be used in form helpers without a problem.

Installation

$ gem install basic_model

Usage

require 'basic_model'

class Message
  include BasicModel
  attr_accessor :name, :email, :content

  # can even include validations
  validates_presence_of :name
end

message = Message.new(:email => 'bob@example.com', :content => 'Hey man!')
message.valid?
message.errors[:name] # => ["can't be blank"]

Using ActiveModel::MassAssignmentSecurity:

require 'active_model'
require 'basic_model'

class Comment
  include BasicModel
  include ActiveModel::MassAssignmentSecurity
  attr_accessor :name, :comment, :spam
  attr_accessible :name, :comment
end

comment = Comment.new(:name => 'Bob', :comment => 'Great Post!', :spam => false)
comment.spam # => nil

Copyright

Copyright (c) 2011 Peter Browne. See LICENSE for details.