title: Rails 3.1 How do I create an API route for "me" that points to the user resource
body: <p>I have a set of API routes in rails as follows</p>
  
  <pre><code>namespace "api" do
     namespace "v1" do
       resources :users do
         resources :posts
         resources :likes
         ...
       end
     end
  end
  </code></pre>
  
  <p>So far, so good. I can GET /api/v1/users/fred_flintstone and retrieve all of the information for that user.</p>
  
  <p>What I would like to do now is add the concept of "me" (ala facebook) such that if the user is authenticated (fred_flintstone), I can also do the following</p>
  
  <p>GET /api/v1/me</p>
  
  <p>GET /api/v1/me/posts</p>
  
  <p>...</p>
  
  <p>I require both sets of routes. So I want to achieve the same results either using GET /api/v1/me/posts OR GET /api/v1/users/fred_flintstone/posts.</p>
  
  <p>I've been through the route tutorial and have googled so a pointer would be as much appreciated as a direct answer.</p>
  
  <p>EDIT:</p>
  
  <p>What I've done that has worked is pretty hacky. I've created a second set of entries in the routes table using a scope:</p>
  
  <pre><code>scope "/api/v1/me", :defaults =&gt; {:format =&gt; 'json'}, :as =&gt; 'me' do
    resources :posts, :controller =&gt; 'api/v1/users/posts'
    resources :likes, :controller =&gt; 'api/v1/users/likes'
    ...
  end
  </code></pre>
  
  <p>And then I added a set_user method that tests for the presence of params[:user_id]. I'm really looking for a way to DRY this up.</p>