Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>Just make some regular non-RESTful routes</h3> <pre><code>map.connect ":controller/:username", :action =&gt; :index map.connect ":controller/:username/:id", :action =&gt; :show </code></pre> <p>This will route <code>/photos/shpigford</code> to the <code>index</code> action on <code>PhotosController</code> and put <code>:username =&gt; "shpigford"</code> in the <code>params</code> hash. The second line will route a URL with an <code>id</code>, like <code>/videos/edgerunner/35467</code> to the <code>show</code> action on <code>VideosController</code> and put <code>:username =&gt; "edgerunner", :id =&gt; "35467"</code> in the <code>params</code> hash.</p> <p>You may want to constrain these routes a bit, so that they don't accidentally match other similar routes. You may also want to add named routes. A more elaborate setup would be:</p> <pre><code>map.with_options :controller =&gt; /photos|videos|blogs/, :username =&gt; /[-a-z0-9]+/, :conditions =&gt; { :method =&gt; :get } do |route| route.user_assets ":controller/:username", :action =&gt; :index route.user_asset ":controller/:username/:id", :action =&gt; :show, :id =&gt; /\d+/ end </code></pre> <p>The <code>with_options</code> block applies its options to all the route definitions inside it, so that we don't have to repeat them every time. What this does, <em>in addition to the basic setup above</em>, is;</p> <ul> <li>Makes sure that the first segment is one of the three controllers we have (Otherwise it would happily accept <code>/zombies/fandango</code> and try to execute the index action of a nonexistent <code>ZombiesController</code> to fail miserably)</li> <li>Makes sure that the second segment(<code>username</code>) consists only of lowercase ASCII letters, numbers and dash.</li> <li>Accepts only HTTP GET requests. POST, PUT and DELETE aren't welcome.</li> <li>Defines these routes as <strong>named routes</strong> so that you can call <code>user_assets_path(:photos,'edgerunner')</code> in your views to render <code>/photos/edgerunner</code></li> <li>Makes sure the third segment(<code>id</code>) digits only, so it does not match <code>/photos/clouds/nimbus</code></li> </ul>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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