Tag: activerecord

Polymorphic Single Table Inheritance (STI)

March 30th, 2010, Comments Off

Migration:

create_table :addresses do |t|
….
t.references :addressable, :polymorphic => true
t.string :type
t.timestamps
end
Address Models:
class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
end
class InvoiceAddress < [...]

Rails: Black Box Testing Complex Models

July 4th, 2009, 8 Comments

In this article I will show you how you can perform complete end-to-end testing of very complex models using a method called Black Box Testing. I will demonstrate a solution that scales to hundreds of tests and upwards, without having to write any additional code or fixtures for each one.
The method I am going to [...]

Understand Named_scope in 60 seconds

June 28th, 2009, 1 Comment

Named scope was introduced in Rails 2.x, it allows you to filter a selection of records easily and repeatedly, without having to write finder SQL all the time.

class Customer < ActiveRecord::Base
has_many :carts
end

class Cart < ActiveRecord::Base
belongs_to :customer
named_scope :completed, :conditions => ["NOT ISNULL(completed_at)"]
end

Example of self-model scoping and finding:

# All completed carts [...]

FIX: TypeError: wrong argument type nil (expected Module)

April 29th, 2009, Comments Off

If you were using an old ARMailer gem, then removed it and installed another, more frequently updated version, (eg, “adzap-ar_mailer” from Github), you might receive the following error when attempting to send mail:
TypeError: wrong argument type nil (expected Module)
from /usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/helpers.rb:109:in `extend’
from /usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/helpers.rb:109:in `initialize_template_class’
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/object/misc.rb:39:in `returning’
from /usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/helpers.rb:108:in `initialize_template_class’
from /usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/base.rb:564:in `render’
from /usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/base.rb:552:in `render_message’
from /usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/base.rb:493:in `create!’
from /usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.2/lib/action_mailer/base.rb:452:in `initialize’
from [...]

Feed

http://www.mendable.com / activerecord