0

Sorry that I don't have the proper terminology to more concisely describe my database design question. Put in an example scenario:

  • User Charley logs onto a forum ("forum" merely as example app here), and before he is taken to the forum interface he must select which room he wants to go into. The only rooms available are "People into drama" and "People into scifi". Charley is dissatisfied with the selection, and has the ability to make his own room called "People into action", which he then choose to go into. "People into action" has the complete same forum interface as the other rooms, except is unpopulated.

  • User Franny logs onto the same forum app, and now sees there are 3 rooms, including the one Charley previous created. She could then also create her own room, or go into the room Charley has just created.

*For additional clarification, I envision /roomname1/forum and /roomname2/forum, where the forum is the same app with the same display and functions, but the posts it show would be different based on first part of the URI with roomname. What I have difficulty understanding is how to properly associate a post's post.room (given that a room has_many posts, and a post belongs_to a room) with what the first part of the URI where the roomname is identified.

I have just recently completed the Hartl's Rails Tutorial, and thought I'd get more experience making my own modifications to the default Twitter-like app. My goal here would be to set up these "rooms" where users could see the universe of microposts associated only with the "room" they are in, and not others.

Thanks for your help!

daspianist
  • 5,336
  • 8
  • 50
  • 94

1 Answers1

1

There are many ways you could do this, here is a quick high level that should get you started.

  • Create a model and controller (eg. Room/RoomsController)
  • RoomsController could be RESTfull
  • Define your routes
  • User goes to Rooms controller, index action and will see a list of rooms.
  • User can see all rooms and Add/Enter a Room (Enter could be your show action, add could be create)

You could build and add to this to enable users to delete/edit rooms they have created as a next step perhaps. You may want to associate posts, so they could belong_to for example. Hope this helps get you started!

Community
  • 1
  • 1
cih
  • 1,960
  • 1
  • 16
  • 27
  • Thanks for the helpful steps. Just to dig a bit deeper about associating posts - I understand the basic concepts about table relationships, and was wondering how I could set up the relationships so posts automatically `belongs_to` a new room after a user has created. From my limited experience, I have established the relationships manually, from data that are already in existence rather than anticipating new ones to be created by a user. – daspianist Jan 08 '13 at 02:53
  • You want to create a new room and associate it with post each time a post is created? You should take a look at callbacks, perhaps an after_create in your Post model and then you can write a method that associates the created post with a room based on a condition. However I would recommend doing something in your controller action that creates the post and just save a post.room = Room.create or perhaps find_or_create_by something like that. Let me know if you need more clarification. – cih Jan 08 '13 at 09:43
  • Thanks for the follow up. I added some additional clarification in the body of the comment. – daspianist Jan 08 '13 at 15:16