Created
January 22, 2011 22:02
-
-
Save caike/791540 to your computer and use it in GitHub Desktop.
SEO friendly topic url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Topic < ActiveRecord::Base | |
(...) | |
def to_param | |
"#{id}-#{name.parameterize}" | |
end | |
(...) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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