Adding error with array of checkbox

def group_permission
@role_combo = Role.find(:all, :select => ‘id,
role_name’).collect { |r| [r.role_name, r.id] }
@roles = Role.find(:all, :select => ‘id, role_name’)
@pages = Page.find(:all)
#@page_roles = PagesRole.find_by_sql(“Select add, update,
delete From pages_roles”)
@page_list = Page.find(:all, :select => ‘id, page_name’)
@permission = PagesRole.find_by_sql("Select role_id,
GROUP_CONCAT(CAST(page_id AS CHAR)) As pages, " +
"GROUP_CONCAT(CONCAT(CAST(pr.added AS CHAR), " +
"CAST(pr.updated AS CHAR), CAST(pr.deleted AS CHAR))) AS
permissions " +
"From pages_roles as pr " +
"Group By role_id " +
“Order By role_id, page_id”).collect { |p| p.attributes
}
if request.post?
begin #2
form = params[:pages_role]
rec_affected = 0
PagesRole.transaction do
#clear the old records first
rec_affected = PagesRole.delete_all([“role_id = ?”,
form[:role_id]])
#add new record
if params[:chbox]
debugger
#params[:chbox].each do |key,value|
1.upto(params[:chbox].length-18) do |check|

          if params[:chbox] == 1
             params[:chbox].squeeze!(" ")
             params[:chbox].split(0)
          end
              pr = PagesRole.new
            pr.role_id = params[:pages_role][:role_id]
              pr.page_id = check.to_i
            pr.added = [check]
            pr.updated = [check]
            pr.deleted = [check]
            pr.save!
      end
    end

    end
  rescue => e
    puts "#{e}====================="
    flash[:notice] = "Permission on <b>" +

Role.find(params[:pages_role][:role_id]).role_name +
" group could not be saved"
logger.error(e)
else
if rec_affected > 0
flash[:notice] = “Permission on " +
Role.find(params[:pages_role][:role_id]).role_name +
"
group was successfully updated”
else
flash[:notice] = “Permission on " +
Role.find(params[:pages_role][:role_id]).role_name +
"
group was successfully added”
end
redirect_to :action => ‘group_permission’
end
end
end

Hi sir, i have an error with adding data with array of checkbox when i
added the element in array is increase for examle, in my checkbox i
have 27 checkbox but when i checked on someone checkbox it has added
one more 28 example chbox[] = {“1”,“0”, “0”, “0”, “0”, “0”, “0”, “0”,
“0”, “0”, “0”, “0”, “0”, “0”, “0”, “0”, “0”, “0”, “0”, “0”, “0”, “0”,
“0”, “0”, “0”, “0”, “0”, “0”}

if i check two time chbox[] = {“1”,“0”, “0”, “0”, “1”, “0”, “0”, “0”,
“0”, “0”, “0”, “0”, “0”, “0”, “0”, “0”, “0”, “0”, “0”, “0”, “0”, “0”,
“0”, “0”, “0”, “0”, “0”, “0”, “0”}

i hope u will help my by regard…
thank u.

“0”, “0”, “0”, “0”, “0”, “0”, “0”}
This is a sideeffect of how checkboxes work. As per the html spec, a
checked checkbox submits its value, but an unchecked one submits
nothing.
However a lot of the time, its far more helpgul to get (for example) 1
or 0 than 1 or nothing.
if you use the check_box helper then rails generates a hidden field
tag with the same name and value 0. if the checkbox is unchecked this
value wins (because rails ignores duplicate parameter names), if its
checked then the checkbox wins.
This doesn’t work with arrays though, since they are implemented via
parameter name repetition.

You’ll be better off using check_box_tag rather than check_box and
having the box’s value be the id of the role)

Fred