Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3 nested routes with constraints
    primarykey
    data
    text
    <p>I'd like to use UUIDs in place id standard IDs in routes. This works:</p> <pre><code># UUIDs are used for ids UUID_regex = /([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/ resources :posts, :only =&gt; [:index, :show, :create], :constraints =&gt; {:id =&gt; UUID_regex} </code></pre> <p>That is Rails accepts <code>/posts/fb0f7c67-6f9b-4e2c-a26b-7700bb9b334d</code> fine.</p> <p>When I start nesting them like this, though,</p> <pre><code># UUIDs are used for ids UUID_regex = /([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/ resources :posts, :only =&gt; [:index, :show, :create], :constraints =&gt; {:id =&gt; UUID_regex} do resources :comments, :only =&gt; [:create, :destroy], :constraints =&gt; {:id =&gt; UUID_regex} end </code></pre> <p>Rails starts to complain: <code>No route matches [POST] "/post/fb0f7c67-6f9b-4e2c-a26b-7700bb9b334d/comments"</code></p> <p>What am I missing?</p> <p>Thx in advance.</p> <p>Notes: I'am on Rails 3.2.2 and ruby 1.9.3; <code>rake routes</code> is:</p> <pre><code>post_comments POST /posts/:post_id/comments(.:format) comments#create {:id=&gt;/([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/, :post_id=&gt;/([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/} post_comment DELETE /posts/:post_id/comments/:id(.:format) comments#destroy {:id=&gt;/([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/, :post_id=&gt;/([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/} posts GET /posts(.:format) posts#index {:id=&gt;/([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/} POST /posts(.:format) posts#create {:id=&gt;/([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/} post GET /posts/:id(.:format) posts#show {:id=&gt;/([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/} </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. 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