Recommended Url format for a blog platform
api, rest, ruby, ruby-on-rails, url
Solution
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.
So they would look like this:
# 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
This involves 2 changes in your routes:
1) Getting rid of "/posts/" in your URLs. To do this you can declare your resource like this:
resources :posts, :path => "/"
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).
To do this should override the `to_param` method in your models like this:
class Post < ActiveRecord::Base
def to_param
"{id}-#{title.parameterize}"
end
end
or use the friendly_id gem if you're finding overriding `to_param` difficult.
Problem
I am building a blog platform (RoR), and planing to use the following format, any drawback? ``` # All Users: http://www.example.com/users/ # A single user (123 is the user id, id is needed for uniqueness) http://www.example.com/users/123/peter # All Categories http://www.example.com/categories/ # A single category listing (123 is the cat id, note: job is singular) http://www.example.com/categories/123/job # All Tags http://www.example.com/tags/ # A single tag listing (123 is the tag id, note: car is singular) http://www.example.com/tags/123/car # A single post http://www.example.com/posts/123/my-title ``` Any suggestion or place to improve? Thanks.