sivakrishna.m
Joined: 01 Jan 2008 Posts: 160 Location: Narsipatnam
|
Posted: Wed Jul 01, 2009 3:13 am Post subject: Multiple Select Helper Plugin Usage |
|
|
Selecting multiple elements in a list is sometimes tricky. You may click inadvertably on one item of the list and lost all your previous selection. You are forced to use Ctrl (or Command) clicks to select more than one element.
Multiple Select Helper allows you to create easy to use list for multiple selections from array, hashes, collections or trees. The list is build using checkboxes so you can click easily and you will not lost the elements you clicked before. As drawback you lose the use of the keyboard in the "list".
This multiple selections are very useful in many to many relationships (has_and_belongs_to_many or has_many :through with no obligatory fields).
You can download this plugin at:
http://svn.ruido-blanco.net/multiple_select/trunk
You can find this information at:
http://ruido-blanco.net/blog/rails-multiple-select-helper-plugin
== Using Multiple Select Helper
When you want to store your list of checked options in a "habtm" relationship you could use something like:
# In the model
class Person < ActiveRecord::Base
has_and_belongs_to_many :cities
end
# In the view
<%=
collection_multiple_select(
'person', 'city_ids', City.find(:all), :id, :name
)
%>
# In the controller
@person.city_ids = params[:person][:city_ids]
And you will have all the fruits you have selected linked to the person you
are editing. |
|