Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A couple of things to add:</p> <p>Your redirect match isn't going to work for certain routes - the <code>*api</code> param is greedy and will swallow up everything, e.g. <code>/api/asdf/users/1</code> will redirect to <code>/api/v2/1</code>. You'd be better off using a regular param like <code>:api</code>. Admittedly it won't match cases like <code>/api/asdf/asdf/users/1</code> but if you have nested resources in your api it's a better solution.</p> <p>Ryan WHY U NO LIKE <code>namespace</code>? :-), e.g:</p> <pre><code>current_api_routes = lambda do resources :users end namespace :api do scope :module =&gt; :v2, &amp;current_api_routes namespace :v2, &amp;current_api_routes namespace :v1, &amp;current_api_routes match ":api/*path", :to =&gt; redirect("/api/v2/%{path}") end </code></pre> <p>Which has the added benefit of versioned and generic named routes. One additional note - the convention when using <code>:module</code> is to use underscore notation, e.g: <code>api/v1</code> not 'Api::V1'. At one point the latter didn't work but I believe it was fixed in Rails 3.1.</p> <p>Also, when you release v3 of your API the routes would be updated like this:</p> <pre><code>current_api_routes = lambda do resources :users end namespace :api do scope :module =&gt; :v3, &amp;current_api_routes namespace :v3, &amp;current_api_routes namespace :v2, &amp;current_api_routes namespace :v1, &amp;current_api_routes match ":api/*path", :to =&gt; redirect("/api/v3/%{path}") end </code></pre> <p>Of course it's likely that your API has different routes between versions in which case you can do this:</p> <pre><code>current_api_routes = lambda do # Define latest API end namespace :api do scope :module =&gt; :v3, &amp;current_api_routes namespace :v3, &amp;current_api_routes namespace :v2 do # Define API v2 routes end namespace :v1 do # Define API v1 routes end match ":api/*path", :to =&gt; redirect("/api/v3/%{path}") end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload