Skip to content

Instantly share code, notes, and snippets.

@caike
Created January 22, 2011 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caike/791540 to your computer and use it in GitHub Desktop.
Save caike/791540 to your computer and use it in GitHub Desktop.
SEO friendly topic url
class Topic < ActiveRecord::Base
(...)
def to_param
"#{id}-#{name.parameterize}"
end
(...)
end
class TopicsController < ApplicationController
def index
@topics = Topic.order('mentions desc')
end
def show
# find calls to_i on params[:id]
# so the string part is removed
@topic = Topic.find(params[:id])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment