In this tutorial am going to explain how to set up ruby on rails environment , create a rails application and test that application on Hereoku paas, so that you can see how your application will look and work in production environments. Also i will go through the errors i encountered during the setup process.
I have already written a post for setting up rails environment on ubuntu. Follow this link for that article Rails on Ubuntu
1)Download and install the rails installer from here. Download rails installer for windows.
It will install all the necessary programs like ruby, ruby gems and rails.
2)If your are behind the proxy, you will not be able to install the gems using bundler. So make sure you set the proxy in cmd promt. Eg: set http_proxy= http://your_proxy:port
3)Open command prompt and CD in to sites folder using cd cd:sites. Run the following command to create a new rails application.
rails new my_app
4)Your rails application will be created when the above command is executed. Rails comes with a default webrick web-server, so you don’t have to configure a web server for running your applications locally. Make my_app as your current directory and execute the following command to start the rails server.
$ rails s or
$ rails server
4)In your web browser go to localhost:3000 , you will find the welcome page of the newly created rails application “my_app”.
Now we have a running rails application which is set up locally. We can test our rails application in Heroku, a platform as a service which basically offers free plans for hosting basic applications. So that you know how your application looks in the production environment.
Setting Up Heroku For Rails Application Deployment:
3) Inorder to push your application to heroku server, you need git configured in your system. Git is a opens source version controlling system. You can download and configure git in you system from the following link. Configure Git For Windows And Linux.
Once setup is over, execute $ git init
from your application folder to create the repository for yout application. Which will be later used to push your application to the heroku platform.
4)Open the terminal and cd in to to your app folder and execute the following command to login to your heroku account from the terminal.
$ heroku login
5) Add the pg gem to the gemfile of your application because heroku basically uses postgreSQL. So in production environment we use postgreSQL. Locally we use sqlite.
group :production do
gem 'pg' '0.12.2'
6)Execute $ bundle install –without prodution (This command will quit the production gems from installing in you local system)
7)Execute $ rake assets:precompile
8) Add the files to the git repository using $ git add .
9) Commit the changes to git using $ git commit -a -m “Initial commit” . Here “-a” stands for all and “-m” stands for the comment you want to give for the commit. If you don’t mention -m , git will automatically open the default editor to enter your comments about the commit.
10) Now execute $ heroku create .This command will create a new application container for your rails app with a url , through which you can access your application through web browser. The DNS is a randomly generted unique URL. It also adds the heroku remote git for your application.
11)Ececute $ git push heroku master to push your application to the heroku app container. If you get any error like “public key denied”, ececute $ heroku keys:add command and then execute the push command.
12) Now you can access the demo application from the url provided by heroku. You can also mange your application from the heroku dashboard from heroku website.