Rails 中基于位置的 URL 路由
我是 Rails 新手。我想了解更多关于基于 IP 的位置、地理位置 URL 路由的信息。
我有 2 个问题。
第一个..
基于国家/地区的位置,如何进行 URL 路由?
如果我的 IP 来自美国,我应该被定向到美国主页。
如果我来自英国,我应该从英国主页定向。
如果我来自任何其他国家,我应该被定向到国际主页。
你能帮我解决rails代码吗?你能帮我提供一个好的教程吗?
现在是第二个问题......
如何使用地理位置将人们路由到他们的城市?
假设我从洛杉矶访问网络,我应该被定向到洛杉矶主页。
如果我在一个小镇访问网络,我应该被定向到最近的城市主页。
如果我在国际位置[美国境外说] 那么我应该被定向到国际页面
期待您的帮助
Gautam
I am new to rails. I want to know more about IP based Location, GeoLocation URL routing.
I have 2 questions.
The first one..
Based on the location of the country, how to you have URL routing?
If my IP is from USA, I should be directed towards USA homepage.
If I am from UK, I should be directed from UK homepage.
If I am from any other country, I should be directed towards International homepage.
Could you please help me with the rails code? Could you help me with a good tutorial?
and now the second question....
How to use GeoLocation to route people to their cities?
Lets say I access the net from LA, I should be directed to LA homepage..
If I am accessing the net at a small town, I should be directed towards closest city homepage..
If I am at an international location [ outside USA say ] then I should be directed towards International page
Looking forward for your help
Gautam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要根据请求的 IP 估计位置,您应该查看 Geokit。
存储位置后,您可以根据他们在会话中的位置简单地渲染您选择的模板。您可以为所有访问者保留相同的 URL 结构,同时根据每个访问者的请求来源呈现特定的模板。
正如您所看到的,GeoKit 附带了一个漂亮的助手来完成您想要的操作 - 它将位置存储在访问者会话[:geo_location] 变量中。
希望有帮助!
To estimate location based on the IP of the request you should look at Geokit.
Once you have the location stored you could simply render the template of your choosing based off the location they have in their session. You can retain the same URL structure for all visitors while rendering each of them specific templates based on their requests origin.
As you can see GeoKit comes with a nifty helper for doing just what you want - it will store the location in the visitors session[:geo_location] variable.
Hope that helps!