开发者

Location based URL routing in Rails

I am new to rails. I want to kn开发者_Go百科ow 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


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.

class ApplicationController < ActionController::Base
  geocode_ip_address
end

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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜