Topic: Restful Routing - Belongs to two model

So I have a problem with how to create restful routes if a certain model belongs to two models.
For instance, if I have a chat room like application where users can ask questions. Then the Question Model would belong to the User model as well as the Room Model.
So then I think it would be the most logical if I used nested resources which would generate routes like:
/user/:user_id/questions (routes to "questions#index")
and
/room/:room_id/questions (routes to "questions#index")


The problem comes up when I try to identify what which parent route it came from in my questions controller.
I know that if the url was
/user/:user_id/questions
then params[:user_id] = :user_id
and params[:room_id] = nil
and vice versa. But I'm not really sure as to what to do next
The best I've done so far is

class QuestionsController < ApplicationController

def index
  @posts = @parent.questions
end
#...restful actions...

private
def get_parent
  @parent = Room.find_by_id(params[:room_id]) || User.find_by_id(params[:user_id])
end

Last edited by czhu12 (2013-05-03 22:01:03)