Handling strange Rails URLs

Came across an interesting situation where my Rails application was going to be receiving URLs with characters like - (dash) and . (period or dot). Something like this:

http://example.com/my_controller/action-with-odd.characters

Ruby doesn’t allow dashes or periods in identifiers, so this was going to cause a problem with method naming. I couldn’t figure out how to handle this from the web and so I dove into the source and found that when the action method doesn’t exist Rails calls a catch all method called perform_action. Adding my logic to this method worked well. Looks something like this:

def perform_action
  ...
end

[tags]rails urls,ruby identifiers[/tags]

2 Responses to “Handling strange Rails URLs”

  1. Anton Says:

    Check out this post here, i think it is a cleaner way to solve your problem.

  2. Anton Says:

    haha, forgot the link

    http://skwpspace.com/2007/02/27/rails-12-breaks-url-routing-with-dots/

Leave a Reply