All threads / What is the best way to determine the country/currency for a user?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

What is the best way to determine the country/currency for a user?

William Gillett asked in Rails

I am using a similar set-up as gorails - devise for registration and stripe for subscriptions. I have separate plans for each currency were are going to market to (USD, CAD, GBP). But I want to offer up the subscription options to the user in their currency - what is the best way to do this short of asking them - what country do you live in? I would like to make an intelligent guess and then allow them to change it if needed.

Check out the Geocoder gem => https://github.com/alexreisner/geocoder and http://stackoverflow.com/questions/34816490/get-remote-ip-address-in-rails-model

What you'll want to do is snag the IP in the controller with something like
@request_ip = request.ip then geocode @request_ip for the country.

You can really use just about any geocoding service that can do the ip address to physical address conversion.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.