Getting an array of ids from form checkboxes?

Is it possible to set up a list of checkboxes so that the form
parameters are given in an array (eg {“delete_list” => [3,6,7]}) ?

At the moment I’m using
<%= check_box_tag “delete_list[#{post.id}]” %>

…which gives parameters looking like {“delete_list” => {“3” => “1”,
“6” => “1”, “7” => 1}}, which seems unnecessarily ugly…

Any suggestions?

Jon

Hi –

On Mon, 7 Aug 2006, Jonathan del Strother wrote:

Is it possible to set up a list of checkboxes so that the form parameters are
given in an array (eg {“delete_list” => [3,6,7]}) ?

At the moment I’m using
<%= check_box_tag “delete_list[#{post.id}]” %>

…which gives parameters looking like {“delete_list” => {“3” => “1”, “6” =>
“1”, “7” => 1}}, which seems unnecessarily ugly…

Any suggestions?

Try this (tweaked as needed):

<% @posts.each do |post| %>
<%= check_box_tag “delete_list[]”, post.id %>
<% end %>

You should end up with params[:delete_list] being an array of the
boxes you’ve checked.

David


http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <-----
http://dablog.rubypal.com => D[avid ]A[. ]B[lack’s][ Web]log
http://www.manning.com/black => book, Ruby for Rails
http://www.rubycentral.org => Ruby Central, Inc.

On 7 Aug 2006, at 16:42, [email protected] wrote:

…which gives parameters looking like {“delete_list” => {“3” =>
You should end up with params[:delete_list] being an array of the
boxes you’ve checked.

Perfect, thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs