Acts As Dropdown Plugin
I saw a post on Monday morning written by courtney over at http://habtm.com called “Handy Select Functions”. I had recently begun building this type of functionality into some of the models in my current application, but when I saw this, I immediately thought “Wow, that’s much better!”
After adding these methods to a library file and trying it out in my application, I began wondering if the implementation might not be even better if the whole thing were in a plugin. Within a few hours acts_as_dropdown was born, allowing you to create dropdowns very easily by just doing the following in your model:
class State < ActiveRecord::Base
acts_as_dropdown
end
and then using the to_dropdown method in the view along with the select form helper:
<%= select(“person”, “state_id”, State.to_dropdown) %>
<select name=”person[state_id]”>
<option value=”1”>Alabama</option>
<option value=”2”>Alaska</option>
<option value=”3”>Arizona</option>
…
</select>
Feel free to check out all the nitty gritty information on the acts_as_dropdown product page, or by checking out the plugin from my SVN repository at http://www.delynnberry.com/svn/code/rails/plugins/acts_as_dropdown/.
So, check it out in your own project and let me know what you think!