How Do You Encrypt URLs?

Couldn't you f.ex add an URL field in the DB to which you assign some
random string like xWa2IUhkjwq23 when you create the page, and then
you could use:

@page = Page.find_by_url(params[:url])

in your Page model you could also add the following:

def to_param
  url
end

That returns the url-parameter we added instead of the ID in cases
where the ID would normally be returned. Remember that you have to use
find_by_url when doing this!

You could also use the following

# Returns somethink like this
# 21-asdKjiWAOdl
# which would be rather easy to guess if the user
# isn't totally dumb
def to_param
  "#{id}-#{url}"
end

Rails will extract the ID when it needs it with some magic, but the
addresses are going to be a lot easier to guess! In this case you
could just use the normal Page.find()

Your routes could look something like this:

map.connect ":controller/:action:/:url"

Hope this helps.

S

Here is a change to my previous post:

If you want URLs like this:

domain.com/show/XyAdcZdF

you would have to make your routes look more like this:

map.connect ':action:/:url', :controller => 'the_controller'