Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
BasicModel is a tiny Module that complies with the ActiveModel API
Ruby Shell
tag: v0.3.1

Fetching latest commit…

Cannot retrieve the latest commit at this time

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.

Something went wrong with that request. Please try again.