README

Path: vendor/plugins/acts_as_selectable/README
Last Update: Thu May 31 11:07:12 -0500 2007

Acts as Selectable

Provides a select_options method for your ActiveRecord classes that maps to the Rails select form helper format.

Install with:

  script/plugin install svn://rubyforge.org/var/svn/slantwise/acts_as_selectable/trunk

Example:

  <%= f.select :types, Type.select_options %>

This replaces the following code:

  <%= f.select :types, Type.find(:all).map {|t| [t.name, t.id] } %>

To use, just add acts_as_selectable to the model you want to be selectable. By default, it will find all records, and will use the name method for the option label and id for the option form value. Override like this:

  acts_as_selectable  :find_with => 'find_active',
                      :name_field => 'title',
                      :id_field => 'abbreviation'

In this example, find_active is a class method that returns an array of ActiveRecord instances, title is a instance method (or DB column) that returns the visible label for the field, and abbreviation is an instance method (or DB column) that is passed when you submit the web form.

[Validate]