Ruby on Rails Friday, February 25, 2011


On 25 Feb 2011, at 10:27, Colin Law wrote:

All the classes inside 'models' folder are considered as ActiveRecord
classes and Rails will try to find a corresponding table in the
database named as plural of the model. It's a convention; To bypass it
and have a model independent from ActiveRecord class, create it in
'lib' folder and require it in the class where you need it.

I don't believe that is true.  I understood that as long as the model
does not derive from ActiveRecord then it should not look in the
database.

Indeed it's not true, you can have any class in the models directory. It's up to you as a developer to decide whether it belongs there.

In our applications, it's quite common we have modellike behavior in plain Ruby classes. Heck, with Rails 3, being able to mix in ActiveModel modules in a non-AR class should make it very obvious that a model isn't necessarily a one-on-one with a database table.


Best regards


Peter De Berdt


No comments:

Post a Comment