class Rails::Generators::ActiveModel
instead of self.new.
The only exception in ActiveModel for ActiveRecord is the use of self.build
builder.save # => “@foo.save”
builder = ActiveRecord::Generators::ActiveModel.new “@foo”
receive the calls:
On initialization, the ActiveModel accepts the instance name that will
# => “Foo.get(params)”
Datamapper::Generators::ActiveModel.find(Foo, “params”)
# => “Foo.find(params)”
ActiveRecord::Generators::ActiveModel.find(Foo, “params”)
For example:
string that matches the ORM API.
The API has the same methods as ActiveRecord, but each method returns a
generate customized controller code.
ActiveModel is a class to be implemented by each ORM to allow Rails to
def self.all(klass)
def self.all(klass) "#{klass}.all" end
def self.build(klass, params=nil)
GET new
def self.build(klass, params=nil) if params "#{klass}.new(#{params})" else "#{klass}.new" end end
def self.find(klass, params=nil)
PUT update
GET edit
GET show
def self.find(klass, params=nil) "#{klass}.find(#{params})" end
def destroy
def destroy "#{name}.destroy" end
def errors
POST create
def errors "#{name}.errors" end
def initialize(name)
def initialize(name) @name = name end
def save
def save "#{name}.save" end
def update_attributes(params=nil)
def update_attributes(params=nil) "#{name}.update_attributes(#{params})" end