Acts As Dropdown plugin
Plugin details
Documentation
ruby script/plugin install svn://delynnberry.com/code/plugins/acts_as_dropdown/trunk
Here is a simple example for how to use the acts_as_dropdown plugin. Assuming you have a model that contains a list of states, consider the following code:
class State < ActiveRecord::Base acts_as_dropdown end
Since the plugin automatically assumes the use of the :name and :id attributes of the class for use when creating the text and value attributes of the option tags, you can now easily use the select form helper to create a dropdown of the States:
<%= select("person", "state_id", State.to_dropdown) %>
You can also customize what the to_dropdown method returns using the :value, :text, :conditions, and :order parameters (both at the class level and at the method level. For example:
class State < ActiveRecord::Base acts_as_dropdown :text => "abbreviation", :order => "id DESC" end <%= select("person", "stateid", State.to_dropdown) %>
or just
<%= select("person", "stateid", State.to_dropdown(:text => "name") %>
The plugin also provides a to_dropdown method for the Array class which allows you to easily turn any array into a group of select options. Just like the ActiveRecord class method the Array method assumes the :name and :id attributes for the text and value of the option tag. For example:
@people = People.find(:all, :limit => 5, :order => "id") <%= select("post", "person_id", @people.to_dropdown) %>
Further Documentation
There is currently no advanced documentation for this plugin.
New documentationEdit plugin | Back in time (2 older versions) | Last edited by: maxim_kulkin, 9 months ago

