Your code inside the loop is using the entire role object. I'm not sure why you were able to treat it as a string in the past, but as you've found you can convert to a string with .to_s. If you just want to get the name out, though, it would be much easier to use the .name method, e.g.,
allroles.each do |role|
rolename = role.name
# etc