scambra/devise_invitable — pull request #232 by tonywok (2012-08-30 17:31:28+00:00)
Title: :send over :[]= for assignment of non-db attributes during registration

In our system, when someone invites another user, a join record is creating making those two users collaborators. This can happen in one of two ways, either the invited user exists in the system, or it does not. If the user exists, then they are immediately connected. However, if the user does not exist, the connection is marked as "pending" and an invitation is sent out.

Now, imagine the case in which before accepting the invitation, the invited user came to the app and signed up using the regular devise registrations controller. Devise Invitable handles this by using an around filter that handles destroying the invited user and copying over the "invitation_fields" to the new user.

However, when copying it essentially does this in an around filter:

```ruby
@invitation_info = Hash[resource.invitation_fields.map {|field|
[field, resource[field]]
}]

# yield stuff

resource.invitation_fields.each do |field|
resource[field] = @invitation_info[field]
end
```

I want to be able to add my own attributes to the User model so that they, too, will be copied over to the new user. For example:

```ruby
class User < ActiveRecord::Base
# regular devise stuff
has_many :connections
has_many :collaborators, :through => :connections

def invitation_fields
super << :collaborator_ids
end
end
```

So, now, it would call `resource.collaborator_ids`, returning, say, `[1,2,3]`. Assigning this to the new users `collaborator_ids` *should* re-establishing any join records that had been created at the time the previous user was invited. As it currently stands, `resource[field]` and `resource[field]=` are used. This will set the new resource's collaborator_ids to nil, which will prevent the join records from being created.

So, to fix this, my pull request simply uses `resource.send(field)` instead of `resource[field]` in the RegistrationsController.