# Best way to model user or IP

**URL:** <https://www.ruby-forum.com/t/best-way-to-model-user-or-ip/161115>\
**Category:** Rails\
**Created:** [February 23, 2009, 4:59pm UTC](https://www.ruby-forum.com/t/best-way-to-model-user-or-ip/161115 "2009-02-23T16:59:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcarneiro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e36b37/32.png) [@dcarneiro](https://www.ruby-forum.com/u/dcarneiro)\
**Post date:** [February 23, 2009, 4:59pm UTC](https://www.ruby-forum.com/t/best-way-to-model-user-or-ip/161115/1 "2009-02-23T16:59:40Z")

</div>

I’m writing a wiki-based website from scratch and would like some  
suggestions on the best way to deal with this common situation. A page  
can be edited by a logged-in and registered user or by an anonymous  
visitor. If a user edits the page, the model object representing the  
edit is associated with a user via a user\_id foreign key. But if an  
anonymous visitor can edit the page too, what’s the best way to model  
this?

One idea I’m entertaining is to make a polymorphic relationship  
between the edit or page version and two different classes: a User  
class and an AnonymousVisitor class. But I’m not sure.

Thanks in advance for your tips and suggestions.

---

<div class="post-metadata">

**Author:** ![dcarneiro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e36b37/32.png) [@dcarneiro](https://www.ruby-forum.com/u/dcarneiro)\
**Post date:** [February 23, 2009, 5:00pm UTC](https://www.ruby-forum.com/t/best-way-to-model-user-or-ip/161115/2 "2009-02-23T17:00:52Z")

</div>

I forgot to mention the requirement that if an anonymous visitor edits  
a page, their IP address is recorded.

---

<div class="post-metadata">

**Author:** ![dcarneiro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e36b37/32.png) [@dcarneiro](https://www.ruby-forum.com/u/dcarneiro)\
**Post date:** [February 23, 2009, 6:37pm UTC](https://www.ruby-forum.com/t/best-way-to-model-user-or-ip/161115/3 "2009-02-23T18:37:37Z")

</div>

Create a single row in the user table to represent the anonymous user,  
and associate the IP address with the edit instead of with the user.  
That way you don’t clutter your database with anonymous users but you  
still retain the IP for each edit.

---

<div class="post-metadata">

**Author:** ![dcarneiro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e36b37/32.png) [@dcarneiro](https://www.ruby-forum.com/u/dcarneiro)\
**Post date:** [February 23, 2009, 11:18pm UTC](https://www.ruby-forum.com/t/best-way-to-model-user-or-ip/161115/4 "2009-02-23T23:18:15Z")

</div>

Thanks Sarah.
