Stringgable Shortcuts
- Filed under HTML Helpers, Utilities, and ActiveRecord
- Developed by josh
Stringgable Shortcuts
Shortcuts and extractions I've found from defining a to_s method on my ActiveRecord models.
Example
class Person < ActiveRecord::Base
def to_s
name
end
end
# Shortens link_to arguments
@person = Person.create :name => "David"
link_to @person # => <a href="/people/1">David</a>
# Sets default choices with select method
select("post", "person_id") # => select("post", "person_id", Person.find(:all).collect {|p| [ p.name, p.id ] })
Copyright (c) 2007 Joshua Peek, released under the MIT license
Last updated: August 23, 2007 20:20


