Model without database table?

Is it possible to make a model that does not map to a database table?
If so how?

On Feb 25, 2008, at 7:28 , Ken Le wrote:

Is it possible to make a model that does not map to a database table?
If so how?

A “model” is a class that represents something in the problem domain,
Rails does not assume it is persistent. Just define a class Foo in app/
models/foo.rb without inheriting from AR::Base.

– fxn

I’m studying rails
I am coding depot application in Agile web development with rails book
I have Cart model code like that :

class Cart

attr_reader :items

def initialize
@items = []
end

def add_product(product)
current_item = @items.find {|item| item.product == product}
if current_item
current_item.increment_quantity
else
@items << CartItem.new(product)
end
end

def total_price
@items.sum { |item| item.price }
end
end
above code is same with that of the book
but depot app have a error
Cart class doesn’t inherit from ActiveRecode::Base
But, Error message is like that

c = Cart.new
ActiveRecord::StatementInvalid: Mysql::Error: #42S02Table
‘depots_development.carts’ doesn’t exist: SHOW FIELDS FROM carts

plz, help me~

    1. 25, ¿ÀÈÄ 6:28, Xavier N. ÀÛ¼º:

Sorry for the late answer, maybe it will be usefull for someone else.

You can use the following plugin:
http://agilewebdevelopment.com/plugins/activerecord_base_without_table