I'd prefer more DRY and slightly more effective form making just one query
```ruby
group_count = request.env['REMOTE_USER_GROUP_N'].to_i
if group_count > 0
  group_names = []
  group_count.times { |i| group_names<< request.env["REMOTE_USER_GROUP_#{i+1}"] }
  attrs[:groups] = Usergroup.where(:name => group_names)
end
```