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.