Pete DeVries
2007-Apr-10 18:19 UTC
Passing in lng and lat via URL, integers work but not floats
Using the following gode I am able to get an response
when the lng and lat are integers, but not when they are floats.
http://localhost:3000/section/query/43,-90 # works!
http://localhost:3000/section/query/43.005,-90.336 # does not work :(
How do I pass in lat and lng parameters from the url?
Thanks in advance!
- Pete
#section_controller.rb
class SectionController < ApplicationController
def query
lat = params[:lat]
lng = params[:lng]
s = Section.find_by_sql("SELECT twp, rng, sec FROM sections WHERE
distance( the_geom,''POINT(#
{lng} #{lat})'') = 0")
site = s[0]
loc = site.attributes
@twp = loc["twp"]
@rng = loc["rng"]
@sec = loc["sec"]
render :action => ''query''
end
end
--------
# section.rb
class Section < ActiveRecord::Base
set_primary_key "gid"
end
--------
# query.rhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en">
<head>
<meta http-equiv="content-type"
content="text/html;charset=UTF-8" />
<title>Query Results<%= controller.action_name %></title>
<%= stylesheet_link_tag ''scaffold'' %>
</head>
<body>
<p style="color: green"><%= flash[:notice] %></p>
<p>Township: <%= h @twp %></p>
<p>Range: <%= h @rng %></p>
<p>Section: <%= h @sec %></p>
</body>
</html>
-------
# routes.rb
ActionController::Routing::Routes.draw do |map|
map.connect '':controller/:action/:lat,:lng''
end
---
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
s.ross
2007-Apr-10 23:33 UTC
Re: Passing in lng and lat via URL, integers work but not floats
You''ll should escape the string: link_to(:action => ''query'', :controller => ''section'', :lat => url_encode(lat), :lon => url_encode(lon)) However, it seems the only unsafe character you have is the comma. If you split into lat and lon as I did above, all should be fine for reassembly in your controller as: @whatever = Section.find_by_lat_lon(params[:lat] + '','' params[:lon]) #assuming method exists :) Pete DeVries-2 wrote:> > > Using the following gode I am able to get an response > when the lng and lat are integers, but not when they are floats. > > http://localhost:3000/section/query/43,-90 # works! > > http://localhost:3000/section/query/43.005,-90.336 # does not work :( > > How do I pass in lat and lng parameters from the url? > > Thanks in advance! > > - Pete > > #section_controller.rb > class SectionController < ApplicationController > > def query > lat = params[:lat] > lng = params[:lng] > s = Section.find_by_sql("SELECT twp, rng, sec FROM sections WHERE > distance( the_geom,''POINT(# > {lng} #{lat})'') = 0") > site = s[0] > loc = site.attributes > @twp = loc["twp"] > @rng = loc["rng"] > @sec = loc["sec"] > render :action => ''query'' > end > > end > > -------- > # section.rb > class Section < ActiveRecord::Base > set_primary_key "gid" > end > > -------- > > # query.rhtml > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> > <head> > <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> > <title>Query Results<%= controller.action_name %></title> > <%= stylesheet_link_tag ''scaffold'' %> > </head> > <body> > > <p style="color: green"><%= flash[:notice] %></p> > > <p>Township: <%= h @twp %></p> > <p>Range: <%= h @rng %></p> > <p>Section: <%= h @sec %></p> > > </body> > </html> > > ------- > # routes.rb > ActionController::Routing::Routes.draw do |map| > > map.connect '':controller/:action/:lat,:lng'' > > end > > --- > > > > > >-- View this message in context: http://www.nabble.com/Passing-in-lng-and-lat-via-URL%2C-integers-work-but-not-floats-tf3554838.html#a9930745 Sent from the RubyOnRails Users mailing list archive at Nabble.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Pete
2007-Apr-12 19:42 UTC
Re: Passing in lng and lat via URL, integers work but not decimals, routing errors
Routing Errors with lat,lon. Integers work but not numbers with
decimals.
I suspect that something needs to be modified in the routing to deal
with decimal points.
Any suggestions! Thanks in advance - Pete
Here is the behavior and code.....
http://localhost:3000/table_points/query/43,-90 <- no decimal points
works
renders page with....
Township: 6
Range: 4
Section: 15
http://localhost:3000/table_points/query/43.05,-90.33 <- decimals
points create routing error
renders page with ...
Routing Error
no route found to match "/table_points/query/43.05,-90.33" with
{:method=>:get}
routes.rb
# Install the default route as the lowest priority.
map.connect ''table_points/query/:latitude,:longitude'',
:controller
=> ''table_points'', :action => ''query''
table_points_controller.rb
def query
s = Section.find_by_sql("SELECT twp, rng, sec FROM sections WHERE
distance( the_geom,''POINT(#{lon} #{lat})'') = 0")
site = s[0]
loc = site.attributes
@twp = loc["twp"]
@rng = loc["rng"]
@sec = loc["sec"]
render :action => ''query''
end
On Apr 10, 6:33 pm, "s.ross"
<cwdi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> You''ll should escape the string:
>
> link_to(:action => ''query'', :controller =>
''section'', :lat =>
> url_encode(lat), :lon => url_encode(lon))
>
> However, it seems the only unsafe character you have is the comma. If you
> split into lat and lon as I did above, all should be fine for reassembly in
> your controller as:
>
> @whatever = Section.find_by_lat_lon(params[:lat] + '',''
params[:lon])
> #assuming method exists :)
>
>
>
> Pete DeVries-2 wrote:
>
> > Using the following gode I am able to get an response
> > when the lng and lat are integers, but not when they are floats.
>
> >http://localhost:3000/section/query/43,-90 # works!
>
> >http://localhost:3000/section/query/43.005,-90.336 # does not work :(
>
> > How do I pass in lat and lng parameters from the url?
>
> > Thanks in advance!
>
> > - Pete
>
> > #section_controller.rb
> > class SectionController < ApplicationController
>
> > def query
> > lat = params[:lat]
> > lng = params[:lng]
> > s = Section.find_by_sql("SELECT twp, rng, sec FROM sections
WHERE
> > distance( the_geom,''POINT(#
> > {lng} #{lat})'') = 0")
> > site = s[0]
> > loc = site.attributes
> > @twp = loc["twp"]
> > @rng = loc["rng"]
> > @sec = loc["sec"]
> > render :action => ''query''
> > end
>
> > end
>
> > --------
> > # section.rb
> > class Section < ActiveRecord::Base
> > set_primary_key "gid"
> > end
>
> > --------
>
> > # query.rhtml
> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
> >
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
> > <html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en" lang="en">
> > <head>
> > <meta http-equiv="content-type"
content="text/html;charset=UTF-8" />
> > <title>Query Results<%= controller.action_name
%></title>
> > <%= stylesheet_link_tag ''scaffold'' %>
> > </head>
> > <body>
>
> > <p style="color: green"><%= flash[:notice]
%></p>
>
> > <p>Township: <%= h @twp %></p>
> > <p>Range: <%= h @rng %></p>
> > <p>Section: <%= h @sec %></p>
>
> > </body>
> > </html>
>
> > -------
> > # routes.rb
> > ActionController::Routing::Routes.draw do |map|
>
> > map.connect '':controller/:action/:lat,:lng''
>
> > end
>
> > ---
>
> --
> View this message in
context:http://www.nabble.com/Passing-in-lng-and-lat-via-URL%2C-integers-work...
> Sent from the RubyOnRails Users mailing list archive at Nabble.com.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
s.ross
2007-Apr-12 22:34 UTC
Re: Passing in lng and lat via URL, integers work but not decimals, routing errors
Use url_encode to clean up your url. It''s probably the comma that''s causing you grief. Pete DeVries-2 wrote:> > > Routing Errors with lat,lon. Integers work but not numbers with > decimals. > I suspect that something needs to be modified in the routing to deal > with decimal points. > > Any suggestions! Thanks in advance - Pete > > Here is the behavior and code..... > > http://localhost:3000/table_points/query/43,-90 <- no decimal points > works > > renders page with.... > > Township: 6 > Range: 4 > Section: 15 > > > http://localhost:3000/table_points/query/43.05,-90.33 <- decimals > points create routing error > renders page with ... > > Routing Error > > no route found to match "/table_points/query/43.05,-90.33" with > {:method=>:get} > > > routes.rb > # Install the default route as the lowest priority. > map.connect ''table_points/query/:latitude,:longitude'', :controller > => ''table_points'', :action => ''query'' > > table_points_controller.rb > > def query > s = Section.find_by_sql("SELECT twp, rng, sec FROM sections WHERE > distance( the_geom,''POINT(#{lon} #{lat})'') = 0") > site = s[0] > loc = site.attributes > @twp = loc["twp"] > @rng = loc["rng"] > @sec = loc["sec"] > render :action => ''query'' > end > > On Apr 10, 6:33 pm, "s.ross" <cwdi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> You''ll should escape the string: >> >> link_to(:action => ''query'', :controller => ''section'', :lat => >> url_encode(lat), :lon => url_encode(lon)) >> >> However, it seems the only unsafe character you have is the comma. If you >> split into lat and lon as I did above, all should be fine for reassembly >> in >> your controller as: >> >> @whatever = Section.find_by_lat_lon(params[:lat] + '','' params[:lon]) >> #assuming method exists :) >> >> >> >> Pete DeVries-2 wrote: >> >> > Using the following gode I am able to get an response >> > when the lng and lat are integers, but not when they are floats. >> >> >http://localhost:3000/section/query/43,-90 # works! >> >> >http://localhost:3000/section/query/43.005,-90.336 # does not work :( >> >> > How do I pass in lat and lng parameters from the url? >> >> > Thanks in advance! >> >> > - Pete >> >> > #section_controller.rb >> > class SectionController < ApplicationController >> >> > def query >> > lat = params[:lat] >> > lng = params[:lng] >> > s = Section.find_by_sql("SELECT twp, rng, sec FROM sections WHERE >> > distance( the_geom,''POINT(# >> > {lng} #{lat})'') = 0") >> > site = s[0] >> > loc = site.attributes >> > @twp = loc["twp"] >> > @rng = loc["rng"] >> > @sec = loc["sec"] >> > render :action => ''query'' >> > end >> >> > end >> >> > -------- >> > # section.rb >> > class Section < ActiveRecord::Base >> > set_primary_key "gid" >> > end >> >> > -------- >> >> > # query.rhtml >> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >> > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> >> >> > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> >> > <head> >> > <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> >> > <title>Query Results<%= controller.action_name %></title> >> > <%= stylesheet_link_tag ''scaffold'' %> >> > </head> >> > <body> >> >> > <p style="color: green"><%= flash[:notice] %></p> >> >> > <p>Township: <%= h @twp %></p> >> > <p>Range: <%= h @rng %></p> >> > <p>Section: <%= h @sec %></p> >> >> > </body> >> > </html> >> >> > ------- >> > # routes.rb >> > ActionController::Routing::Routes.draw do |map| >> >> > map.connect '':controller/:action/:lat,:lng'' >> >> > end >> >> > --- >> >> -- >> View this message in >> context:http://www.nabble.com/Passing-in-lng-and-lat-via-URL%2C-integers-work... >> Sent from the RubyOnRails Users mailing list archive at Nabble.com. > > > > > >-- View this message in context: http://www.nabble.com/Passing-in-lng-and-lat-via-URL%2C-integers-work-but-not-floats-tf3554838.html#a9969772 Sent from the RubyOnRails Users mailing list archive at Nabble.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
gene.tani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Apr-13 13:25 UTC
Re: Passing in lng and lat via URL, integers work but not decimals, routing errors
On Apr 12, 12:42 pm, "Pete" <pete.devr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Routing Errors with lat,lon. Integers work but not numbers with > decimals. > I suspect that something needs to be modified in the routing to deal > with decimal points. > > Any suggestions! Thanks in advance - Pete >the periods in URLs issue discussed a couple threads down: http://skwpspace.com/2007/02/27/rails-12-breaks-url-routing-with-dots/ http://groups.google.com/group/rubyonrails-talk/browse_frm/thread/6e8c2c7c9f5c69a6/# --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Pete
2007-Apr-13 20:27 UTC
Re: Passing in lng and lat via URL, tried requirements to get around decimal point
I tried my code without using decimals by multiplying the longitude
and latitudes by 1000 and
the dividing them again once they were passed to the controller. This
works so it seems
the decimal point was the problem.
However using the "requirements" in the routes.rb does not seem to fix
the problem. I still have a routing error, below is the error message
and my routes.rb
no route found to match "/table_points/query/43.05,-90.89" with
{:method=>:get}
routes.rb
map.connect ''table_points/query/:latitude,:longitude'',
:controller
=> ''table_points'', :action => ''query'',
:requirements => { :latitude
=> /.*/, :longitude => /.*/ }
Any suggestions would be greatly appreciated :-)
Thanks in Advance,
-Pete
On Apr 13, 8:25 am,
"gene.t...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org"
<gene.t...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On Apr 12, 12:42 pm, "Pete"
<pete.devr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Routing
Errors withlat,lon. Integers work but not numbers with
> > decimals.
> > I suspect that something needs to be modified in the routing to deal
> > with decimal points.
>
> > Any suggestions! Thanks in advance - Pete
>
> the periods in URLs issue discussed a couple threads down:
>
>
http://skwpspace.com/2007/02/27/rails-12-breaks-url-routing-with-dots/http://groups.google.com/group/rubyonrails-talk/browse_frm/thread/6e8...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---