Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's all depends on what's the most important subject of your app. Supposing that the main subject of the app is posts, then the URLs for posts would have to be "closer" to the root url.</p> <p>So they would look like this:</p> <pre><code># A single post http://www.example.com/123-my-post-title # All Users: http://www.example.com/users/ # A single user (supposing the username must be unique) http://www.example.com/users/peter # All Categories http://www.example.com/categories/ # A single category listing (supposing the category name must be unique) http://www.example.com/categories/job # All Tags http://www.example.com/tags/ # A single tag listing (supposing tags must be unique) http://www.example.com/tags/car </code></pre> <p>This involves 2 changes in your routes:</p> <p>1) Getting rid of "/posts/" in your URLs. To do this you can declare your resource like this:</p> <pre><code>resources :posts, :path =&gt; "/" </code></pre> <p>2) Getting rid of the id in all the URLs except of post#show (posts from different users may have the same titles sometimes, if not, you could omit the ID in those cases too).</p> <p>To do this should override the <code>to_param</code> method in your models like this:</p> <pre><code> class Post &lt; ActiveRecord::Base def to_param "{id}-#{title.parameterize}" end end </code></pre> <p>or use the <a href="https://github.com/norman/friendly_id" rel="nofollow">friendly_id gem</a> if you're finding overriding <code>to_param</code> difficult.</p>
 

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