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]

This entry was posted in Rails, Ruby. Bookmark the permalink.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>