Skip to content

Instantly share code, notes, and snippets.

View ianterrell's full-sized avatar

Ian Terrell ianterrell

  • University of Virginia
  • Charlottesville, VA
View GitHub Profile
[13:20][ian@ian-terrells-macbook-pro:~/src/test/i18ntest]$ ./script/console
Loading development environment (Rails 2.3.2)
>> o = Order.create
=> #<Order id: 1, created_at: "2009-05-25 17:21:00", updated_at: "2009-05-25 17:21:00">
>> t = OtherThing.create
=> #<OtherThing id: 1, created_at: "2009-05-25 17:21:05", updated_at: "2009-05-25 17:21:05">
>> o.payments.create
=> #<Payment id: 1, payable_id: 1, payable_type: "Order", created_at: "2009-05-25 17:21:11", updated_at: "2009-05-25 17:21:11">
>> o.payments.create
=> #<Payment id: 2, payable_id: 1, payable_type: "Order", created_at: "2009-05-25 17:21:13", updated_at: "2009-05-25 17:21:13">
class Book < ActiveRecord::Base
belongs_to :publisher
belongs_to :author, :select => [:id, :name], :conditions => "name != 'jax'"
belongs_to :another, :class_name => "SomeModel"
has_many :revisions
has_many :editors, :through => :revisions
has_one :something
class Book extends ActiveRecordModel {
static $belongs_to = array(
array('publisher'),
array('author', 'readonly' => true, 'select' => 'name', 'conditions' => "name != 'jax'"),
array('another', 'class_name' => 'SomeModel')
);
static $has_many = array(
array('revisions'),
array('editors', 'through' => 'revisions')
@ianterrell
ianterrell / gist:111115
Created May 13, 2009 16:38
Implementation for Authorization plugin
# This lets you define user roles as methods,
# i.e. checking the role of "admin" on a user
# will delegate to user.admin?
#
# This is helpful because in ActiveRecord, boolean
# attributes automatically have their query method
# defined; a boolean field "admin" will define
# the "admin?" method for you.
#
# If your logic is more complex, you can write your