Interesting usage for polymorphic asset model :)

stevo Jan 22, 2010 1 thank

...to automatically define default scopes of inherited classes.

class Asset < ActiveRecord::Base

belongs_to :resource, :polymorphic => true before_save :set_asset_type

def set_asset_type self.asset_type = self.class.name end

def self.inherited(subclass) super...

Argument Accepted

nhance Jan 19, 2010 2 thanks

Accepts a single argument record_separator which is the character or string to chomp.

Why isn't this shown in the method def at the top?

Default fallback

Vidmantas Jan 11, 2010 2 thanks

You can specifly :default option which is useful when the translation is not found. For example:

t(:this_translation_doesnt_exist, :default => 'Ooops!')
# => Ooops!

Or even any number of "fallbacks" - the first not nil is returned:

t(:missing, :default => [:missing_too, :existing, 'S...

Includes all ancestors

mcmire Jan 11, 2010

May be helpful to know that this returns true if B is any ancestor of A, not just a direct one. As an example:

class Foo; end class Bar < Foo; end class Baz < Bar; end

Foo >= Bar #=> true Foo >= Baz #=> true

Includes all ancestors

mcmire Jan 11, 2010

May be helpful to know that this returns true if B is any ancestor of A, not just a direct one. As an example:

class Foo; end class Bar < Foo; end class Baz < Bar; end

Foo > Bar #=> true Foo > Baz #=> true

Includes descendants

mcmire Jan 11, 2010

May be helpful to know that this returns true if A is any descendant of B, not just a direct one. As an example:

class Foo; end class Bar < Foo; end class Baz < Bar; end

Bar <= Foo #=> true Baz <= Foo #=> true

Includes descendants

mcmire Jan 11, 2010

May be helpful to know that this returns true if A is any descendant of B, not just a direct one. As an example:

class Foo; end class Bar < Foo; end class Baz < Bar; end

Bar < Foo #=> true Baz < Foo #=> true

If you want direct descendance try Class#superclass:

Bar.superclass == Foo #=> t...