Browse the Ruby on Rails Community.

You are here: Browse Railsplugins Stringgable Shortcuts

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 # => David

Sets default choices with select method

select("post", "person_id") # => select("post", "person_id", Person.find(:all).collect {|p| [ p.name, p.id ] })

Copyright© 2007 Joshua Peek, released under the MIT license


Homepage: http://projects.wh.joshpeek.com/browser/plugins/stringgable_shortcuts