Skip to content

Instantly share code, notes, and snippets.

@alexreisner
Created September 9, 2009 04:29
Show Gist options
  • Save alexreisner/183467 to your computer and use it in GitHub Desktop.
Save alexreisner/183467 to your computer and use it in GitHub Desktop.
Rails: use friendly (non-numeric) URLs.
##
# Use the +handle+ instead of the +id+ for URLs.
#
def to_param
handle
end
# GET /articles/1
def show
@article = Article.find_by_handle!(params[:id])
...
end
# GET /articles/1/edit
def edit
@article = Article.find_by_handle!(params[:id])
end
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment