Your are here: Home // Posts Tagged With activerecord

ActiveRecord Observers

Podcast: Play in new window | Download About a month ago, I talked about ActiveRecord Callbacks. Observers are a way of moving callbacks out of the Model. Usually this is done to adhere to the Single Responsibility principle. So, for example, programmers will move sending an email when a record is updated or created to an Observer. class UserObserver < ActiveRecord::Observer def after_create(user) ... 

ActiveModel – Making Ruby Classes Behave Like Models

Podcast: Play in new window | Download I’ve been working on an ORM for Cassandra. One of the things I’ve been using to build the ORM is ActiveModel. ActiveModel gives you modules you can add to your class that makes it behave like an ActiveRecord Model. Here are some of the features you can add to your classes with ActiveModel. Attribute Methods Callbacks Dirty Attributes (knowing which attributes... 

Model Associations

Podcast: Play in new window | Download ActiveRecord models are based upon tables in relational databases. This, of course, means that they can be relational. Models can associate in three main ways: one to many, one to one, and many to many. One to many is usually achieved by calling has_many on the model representing the “one” to state that it “has many” of its counterparts. The model... 

ActiveRecord Callbacks

Podcast: Play in new window | Download You can get a full list of the ActiveRecord callbacks here. Callbacks are a handy way of insuring specific behaviors on your models as well as managing the events that follow the callbacks. For example, a before_destroy callback can be called to destroy associated objects. (This is best done on the association with :dependent => :destroy, but it makes... 
Copyright © 2009 Rails Coach. All rights reserved.
Designed by Theme Junkie. Powered by WordPress.