Sunday, August 8, 2010

[Rails] User[17]

In Rails 2.3.8 if you put this in RAILS_ROOT/initializers/

# active_record_extensions.rb
module ActiveRecord
class Base
class << self
def [](index)
find(index)
end
end
end
end


Then you can access like an array:

User[17]

instead of the more verbose:

User.find(17)

Personally, I think it's kinda nice.

David :)

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate