<% for cat in Category.all.sort_by{|i| i.name} do %> <%= check_box_tag cat.id, cat.id, checked = (if pr_div.category && (pr_div.category.split(',').include? cat.id.to_s) then true else false end), {:id => cat.id.to_s+rand(1000).to_s, :onChange => "SetCategories($(this))"}%> <%= cat.name%> <% end %>