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 ActiveRecordclasses and Rails will try to find a corresponding table in thedatabase named as plural of the model. It's a convention; To bypass itand 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
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment