Select multiple models with multiple checkboxes. Rails Way?

I want to display my houses with a checkbox next to each of them, how do
i do it?
I know i could do check_box(“house[]”,“enabled”) if my houses could be
enabled. But what do you do if you just want a list of the ids of the
selected houses?

Any ideas? I’m sooo sure this is stupidly easy. I feel stupid.

I’ve had to do this and it doesnt seem right, although it works:

[view]

<% for @house in @houses %>
<%=check_box “house[]”,“nil?” %>
<% end

[controller]

#this method will return a list of selected house ids:
def get_selected_houses
ids=[]
params[param].each_pair do |key,value|
if value[“nil?”]==“1”
ids << key
end
end
false
end

Any ideas what the rails way of doing this is?

Thanks
Chris

Hello Chris,

2006/9/11, Chris [email protected]:

I want to display my houses with a checkbox next to each of them, how do
i do it?

Look into the MultipleSelect plugin:
http://www.agilewebdevelopment.com/plugins/multiple_select_helper
http://ruido-blanco.net/blog/rails-multiple-select-helper-plugin/

Hope that helps !

François Beausoleil
http://blog.teksol.info/
http://piston.rubyforge.org/