0

According to current best practices a RESTful URL for a given thread on a message board should look something like this:

http://domain/forum/threads/3

It is also a common SEO practice that URLs should contain keywords (slug), so perhaps the above URL could become:

http://domain/forum/threads/3/title-of-this-particular-thread

Now, to edit this thread, again, according to the guidelines I've linked to in the first paragraph, the URL would be:

http://domain/forum/threads/3/edit

What should happen when someone starts a thread with the title of "edit"? How should it be decided if the thread is to be shown or edited?

afarazit
  • 4,907
  • 2
  • 27
  • 51
Wabbitseason
  • 5,641
  • 9
  • 49
  • 60

1 Answers1

1

Instead of http://domain/forum/threads/3/title-of-this-particular-thread

You should be doing http://domain/forum/threads/3-title-of-this-particular-thread

This will prevent conflicts and is just as SEO friendly. There are a few ways to accomplish this, but the easiest is to add a to_param method in your model that does the conversion automatically:

class Thread < ActiveRecord::Base
  to_param
    "#{id}-#{title}"
  end
end

If you need more flexibility than this, or don't want to repeat it in all your models, you can use the friendly_id Gem.

Peter Brown
  • 50,956
  • 18
  • 113
  • 146