Skip to content

Instantly share code, notes, and snippets.

@Papillard
Created July 17, 2013 14:20
Show Gist options
  • Select an option

  • Save Papillard/6020973 to your computer and use it in GitHub Desktop.

Select an option

Save Papillard/6020973 to your computer and use it in GitHub Desktop.
custom urls over-riding ActiveRecord::Base#to_param
# Overload to_param method to custom urls
# Tweet.find(params[:id]) will still work !
class Tweet < ActiveRecord::Base
belongs_to :user
def to_param
"#{id}-#{user.username}" # => url will be /76-Papillard
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment