Rails SEO/Freindly URLs

to get decent SEO URLs in your rails app, app the following snippet to the model in question

  #change the URL of the apps to be more SEO friendly
  def to_param
      "#{id}-#{parameterize}"
  end

that would generate URLs as the following

http://www.barmajeyat.com/apps/1-tajweed

4 comments

  1. You can get the same result with:

    def to_param
    “#{id}-#{name.parametrize}”
    end

    Nothing serious, but looks better :)

  2. aah, There’s a typo in my previous comment. It’s “parameterize”. http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html#M001367

  3. Zaid B. Amireh

    thanks for the tip Faisal, I have updated the post :>

Leave a comment