Rails: How to have dynamic association

Posted by Aaron Dufall on Stack Overflow See other posts from Stack Overflow or by Aaron Dufall
Published on 2012-06-18T12:37:20Z Indexed on 2012/06/18 15:16 UTC
Read the original article Hit count: 157

I'll use an example to explain what behaviour I would like to achieve.

If you had a project management app and you added a task, but not all the contributors are users of the app. So when you adding contributors to the task you can enter a user name or email address.

Here is the part that I'm finding a little tricky. The task model has many contributors which are linked through the user model, but from this point on I want to achieve 2 things.

  1. Store the non members email(this would obviously be quite simple)

  2. If that email address was to create an account it would then link that user to the task and remove the temporally saved email.

This way, when that user creates an account all the related tasks will already be associated with their email.

Is this something that i could achieve with a polymorphic association? or is there something else I should be looking at?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about activerecord