Passing a period as part of an id in show action

I am trying to do the following in a RESTful manner:

I have a web service that accepts an id to deliver a particular
record. Unfortunately, the id that the client will have is not the
usual database sequence number. This mostly works, though, and the
url
looks something like:

http://myservice.com/controller/the_id.xml

That is handled by the “show” action.

Unfortunately, some of the ids that will be passed contain special
characters. I can require that they be encrypted, but the period
seems
to be having a problem. In other words, if the id is “the+id. value”,
the url should be:

http://myservice.com/controller/the%2Bid.+value.xml

where the plus, period and space are transformed. This works for the
plus and space, but the period causes the rest of url to be
considered
the “format” parameter.

Actually, mostly.

I’ve tried on two different servers, running the same version of
rails. One accepts the above url and one doesn’t.

I’ve tried to figure out what is different about the servers. Could
this be caused by an Apache configuration difference? Or a Passenger
difference? I could use a hint about where the transformation of the
%2e to period takes place.


Alternately, what do you do in this situation? It would be trivial to
do this non-RESTfully, by making a custom route, but I was attempting
to be completely RESTful in my web service. Am I just making it hard
on myself?

On 23 May 2011 21:42, paulie [email protected] wrote:

I am trying to do the following in a RESTful manner:

http://myservice.com/controller/the%2Bid.+value.xml

the period causes the rest of url to be considered
the “format” parameter.

Can you change your route, rather than
controller/id.format
can you have:
controller/id/format
This way it wouldn’t matter if there are full stops in the id
(although slashes may become a problem :slight_smile:

controller/id/format
This way it wouldn’t matter if there are full stops in the id
(although slashes may become a problem :slight_smile:

Or tell Rails periods are okay… using a regex… something like…

:requirements => { :id => %r([\w.]+) }

Thanks for the suggestions. I decided to just go the easy way and have
that one entry point not be RESTful. It will look like:

http://myservice.com/controller/get?uri=XXXX

and:

http://myservice.com/controller/get.xml?uri=XXXX

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs