Is it wrong/impossible to pass a float as an id in RAILS 2.x
http://mysite.com/clientversioncheck/1.1
controller:
def clientversioncheck
current_version = 1.1
client_version = params[:id].to_f
if client_version && current_version > client_version
render :text => "update url"
else
render :text => "no update " + current_version.to_s + "server vs. " + client_version.to_s, :status => 404
end
end
If I’m comparing a whole number it’s always fine but if I pass a float as a string the conversion always seems to drop the decimal portion.
So if current_version = 1.0 and I pass 1.0 in the url everything is fine
if current_version = 1.1 and I pass 1.1 in the url client_version evals as 1.0.
I thought . does not need to be escaped in URIs
If I boil things down to simply:
def clientversioncheck
render :text => params[:id]
end
I get the truncation still
For instance: clientversioncheck/2.33 will output 2
I’ve tried the following routes:
map.resources :api, :id => /[A-Za-z0-9\.]+?/, :format => /json|xml|plist|html/
map.resources :api, :requirements => { :resource => /.*/ }
You need to get some looser requirements into the router system as in this one:
The way to do that is to use
:requirementsin one way or another.map.resourcesdoesn’t understand the:idoption or:requirementsso these two won’t work:map.resourcesdoes take a Hash of options though so you won’t get an error when you pass it options that it doesn’t understand.The easiest thing to do is to define an extra route outside of
map.resourcesthat allows a dot in the:id. Something like this:Or:
You can put the
map.connectbefore or after themap.resources.