Detecting User Location with Rails

So building my little web app (An Arabic tool to convert Arabic numbers to their text representation), I needed to detect user’s country to improve the site usability by improving the defaults.

researching, found this to be the simplest way possible. It does not
even require a database. As you will be connecting to third party

– Create an account at

– Once you register, you will get your api key.

– Download geo-ip Ruby Gem (gem has not been updated since March 2012, but it is still working like a charm with even with latest Rails 4)

– Now, all you need to do is to create an initializer file in the folder config/initializers (call it geo-ip):

GeoIp.api_key = ‘YOUR_API_KEY’

– Then you can get the ip of the user by this rails method:

user_ip = request.remote_ip

– From the received ip, you can now get location info of users by calling methods of the geo-ip gem:

country = GeoIp.geolocation(user_ip, :precision => :country)

For all geo ip methods, please the check out the gem documentation

Google Map Marker

Google Map Marker (Photo credit: [ Mooi ])

Deploying Ruby on Rails Applications for Beginners

You always see on Rails forums, rails newbies asking about their best option for hosting their small web app.

In the world of php, deploying is a much simpler process with choices among thousands of good cheap hosts.

When it comes to Rails less options are available, although significantly increasing these days, and process is more complicated.

The biggest issue arises when you are like me a Windows user and developed your app on your Windows machine. Of course, the first thing every other developer may tell you is to move to Linux (Ubuntu is by far the most popular).

Actually moving to Linux for Rails developers may be the right decision which I still have not taken. And this is why I made this blog.

( As you may have already noticed I usually target new rails developers on Windows )

So the most recommended host for beginners, is Heroku, extremely to use and usually it is easy to move your site from your local Windows machine to their servers. The problem with Heroku is their prices. They have a free basic account, but does not offer much, if you get some traffic, soon you will have to upgrade and rate will jump drastically.

After some research I found that my best bet is to use Digital Ocean

Their basic account is for $5 a month, no other Rails host can beat that, trust me.

Now after registering with Digital Ocean, I found it a bit complicated to move my local Rails App to their cloud, so I was introduced to Cloud 66

They say it very clearly: Cloud 66 makes deploying and running of Ruby on Rails apps simple. And it is so true. All you need is your Digital Ocean account, and your app on github. Cloud66 will analyze your code and create the right environment on Digital Ocean.


We need to use Git to upload our code and keep versions of it and calibrating with others in writing code.

Most serious Ruby on Rails developers keep a copy of their code at Git Hub. The free access keeps code public, a model to encourage open source software development, If you need your app to be private you can open a paid private account.
You will have to copy and paste the key of your rails project to your account.
Actually, when you install a Rubyonrails installer for windows, you will get the key. If you don’t have it, please follow these instructions

As per the tutorials am currently doing (am watching the videos not the book…you can buy them from the same site. Trust me they are worth the price. (an am not affiliated in anyway)). and forgive the ugly website layout and the “spammy” feel. It is not.

– There is a .gitignore file in your app folder, where it indicates which files needs to be ignored by git. (think of it like a backup system which need to know which files need not to be included in the sync operation)
Change your .gitignore file content to this. It is the recommended and used one by Michael Hartl.

You can also use this one, frequently updated made by the rails community on github


# See for more about ignoring files.
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
#   git config --global core.excludesfile ~/.gitignore_global

# Ignore bundler config

# Ignore the default SQLite database.
/db/*.sqlite3# Ignore all logfiles and tempfiles.
/tmp# Ignore other unneeded files.

The tutorial teaches basic commands from the git command line.

These are the basics:

$ git add .  (this will add all files listed in the directory we are running the command from, to be included in the further pushing commit, push, pull requests)
$ git commit -m “Initial commit”
$ git status
$ git push -u origin master
$ git remote add origin

I will not go through all details of git in this post.. but if you want to save your time of learning GIT command. You can cheat and use
the Github Windows Client. Am not installing it. At this stage I prefer to learn the commands. It will be easier later for me to understand the ins and outs of the clients

PS: If you feel too serious about learning Git system. Then this the most recommended book and its online for free.

Today's latte, brand-new Git logo!

Today’s latte, brand-new Git logo! (Photo credit: yukop)


Starting with Ruby

Unfortunately I have not been able to post the last couple of days, but this what I have been doing.

Learning Ruby.

Trust me, you will get very discouraged in learning Ruby on Rails if you don’t start with Ruby.

What you need to do first is to complete these two wonderful fun tutorials.

The best thing about them, is that you will be able to practice online. Yes, you can write code and compile it online.

So for now, you will not need to install anything.

These are the two tutorials, the first is easier and more compact and gives you a good overview of the language.

The second covers more topics and is better and more  seriousthan the first.

You must do both. the good news, both are free!

1. Code School , Try Ruby

2. Ruby Monk

I have completed both. And formed a good basis to try to dive into Ruby on Rails.

Once I start learning Ruby on Rails if I find that am always referring to Ruby documents and am getting confused, I will learn more Ruby. Then I will advise for more resources.

Get Rubied Before Getting Railed

Don’t jump into learning Ruby on Rails. I can’t wait for that too. But I already know that a good Ruby on Rails developer is a good Ruby programmer.

Let’s get Rubied before getting Railed.

I think we will love Ruby

Why Ruby?

Many of modern, functional, simple, and nice looking websites are built with Ruby on Rails.

Twitter, Shopify, Hulu to mention a very few.

Official Ruby logo

Official Ruby logo (Photo credit: Wikipedia)

The community seems to be the greatest. And there is a high demand and low availability of engineers. So a job is almost guaranteed after you build a few projects as a proof knowledge and experience. But you will probably be like me, want to build something for yourself, and have your own tech startup rather than working for someone. a lot of today’s tech  entrepreneurs are using Ruby.

And actually what made me decide on Ruby was:

Ruby on Rails framework

This post

Do you really want to get railed?

Who is this blog for?

  • You have just decided to start learning Ruby on Rails.
  • You have written code before. (even a simple Windows application..)
  • You know basic programming concepts and OOP.
  • You have no or minimal experience in Web App development
  • Have basic knowledge of CSS,HTML, Javascript.

If you answer “Yes” or “Kind of” to all of the questions above, you are the right person to follow my blog and get railed with me.

Riding the Rails

Riding the Rails

And now: The first ever free gifts for commenters!

Here is the deal, comment on this post, and tell me about you and why you think you need to follow my journey and get railed.

I will select the three BEST comments, (what is best? show true passion for this blog and convince me of having it).






You will get one of the two below services:

  • – Infographic design of 8 values you provide.
  • – Draw a Simpson character out of your picture
  • – Create a new photo slide show with 30 of your pictures