Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should check out the documentation for <a href="http://api.rubyonrails.org/classes/ActionController/Routing.html" rel="nofollow noreferrer">ActionController::Routing</a>, <a href="http://api.rubyonrails.org/classes/ActionController/Resources.html" rel="nofollow noreferrer">ActionController::Resources</a> for RESTful routes, and a handy <a href="http://guides.rubyonrails.org/routing.html" rel="nofollow noreferrer">Rails Guide</a> on the topic. There are also a number of Railscasts <a href="http://railscasts.com/episodes?search=routes" rel="nofollow noreferrer">regarding routes</a>.</p> <p>Something as simple as <code>map.connect :path/:link, :controller =&gt; :companies</code> would work, but it may cause some problems depending on your existing routes and is not RESTful. If it does not cause any conflicts, this would allow you to do what you're asking for.</p> <p>You can add constraints to the route using the :requirements option to narrow down what is considered a match:</p> <pre><code>map.company_link :company/:link, :requirements =&gt; { :company =&gt; /[\w\-]+/, :link =&gt; /[\w\-]+/ } </code></pre> <p>This would only match word and dash ('-') characters in the url, and I believe the default routes will still work properly. I also made it a named route with <code>map.company_link</code> so Rails creates a set of url helpers allowing easy reference to your route: <code>company_link_path(:company =&gt; "Bechtel", :link =&gt; "railwayproject")</code></p> <p>If you want to stick with the REST way of doing this would be:</p> <pre><code>map.resource :companies do |company| company.resources :links end </code></pre> <p><code>/companies/1/links/2</code> would get passed to the show action of the links_controller with the company and link ids as params. This is explained further in the <a href="http://guides.rubyonrails.org/routing.html#nested-resources" rel="nofollow noreferrer">nested resources</a> section of the previously mentioned Rails Guide. Normally, you would use the :shallow => true option, because the link id of 2 is already unique and does not need to be nested under companies. The real value of the nested route is showing all of the links with <code>/companies/1/links</code> and all other actions going directly to the individual link <code>/links/2</code>. </p>
    singulars
    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.
 

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