Check box

iam having a view of table which have contents and i want to add up a
check box for each column how can i implement.please help me.

There are probably better ways, but here’s how I would do it:

Create a check box for every row, and assign it a name that’s based on
the id of the record displayed, along the lines of:

for item in @items

<%= check_box 'delete_check_' %>

For each checkbox that is checked, the form will return
params[:delete_check_xxx] (xxx being the id number) So in your
controller, check for the existence of params[:delete_check_xxx] while
xxx < @items.length, for each one that’s found, find the item by the id
and destroy it.

Better would be something like:

<%= check_box_tag “delete_check[#{}]”, value = true %>

Then the params come into your method as a hash of results:

Parameters: {“action”=>“index”, “delete_check”=>{“23”=>“true”,
“47”=>“true”}, “controller”=>“whatever”}

Then you can iterate over all the checked items:

params[:delete_check].each_key do |delete_id|


David S.

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