Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Multiple Models: How could I do this?

25 views
Skip to first unread message

Jonovono

unread,
Aug 28, 2012, 8:52:08 PM8/28/12
to pluginaw...@googlegroups.com

I am making an app similar to Chatroulette.

I am using Ruby on Rails, so I am looking to use "state machine".

What I am not sure how to do is make the state depend on the state of another model or another object of the same class.

For example, in my databases right now, I have a UserConversation and Message table. The user has many conversations and each conversation belongs to two other users, so it's "many to many". The User would either be in one of three states: inactivetalking, or waiting. When the user enters the state of waiting, if there is another user in the waiting state they enter the conversation state together. If not the user waits until a user enters the waiting state. When one of the users ends the conversation the user either go into waiting or inactive state, depending on if they pressed "next partner" or stop talking. When this happens that conversation goes into the end state. So a conversation would have two states: active and ended.

Any suggestions on how this should be achieved would be awesome.

Reply all
Reply to author
Forward
0 new messages