Forum: Ruby on Rails best way to model user or IP

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
004e78a7e0aaf9f1eb0009668cd84b1a?d=identicon&s=25 Daniel Choi (dchoi)
on 2009-02-23 16:59
(Received via mailing list)
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.
004e78a7e0aaf9f1eb0009668cd84b1a?d=identicon&s=25 Daniel Choi (dchoi)
on 2009-02-23 17:00
(Received via mailing list)
I forgot to mention the requirement that if an anonymous visitor edits
a page, their IP address is recorded.
92497f51734ed56687928d5fd68d870a?d=identicon&s=25 Sarah Mei (Guest)
on 2009-02-23 18:37
(Received via mailing list)
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.
004e78a7e0aaf9f1eb0009668cd84b1a?d=identicon&s=25 Daniel Choi (dchoi)
on 2009-02-23 23:18
(Received via mailing list)
Thanks Sarah.
This topic is locked and can not be replied to.