Monday, June 10, 2013

Ruby on Rails tutorial

I began this tutorial, http://ruby.railstutorial.org/ruby-on-rails-tutorial-book, about a year ago and got through a few chapters.  However, I lost momentum, and for reasons that I do not remember at all, I stopped working on Ruby development.  Since I got a new computer and I probably forgot everything that I learned, I'm going to have to start from scratch and go through the tutorial again from the beginning.

Installing ruby, rvm, gem, rails ...
There seems to be a lot of stuff needed to install and configure in order for you to begin coding.  There really isn't anything fun or interesting to learn as you install this software.  You just have to do it, and hope that you didn't make some silly mistake that comes back to bite you later.   After a few minutes of downloading, compiling and other magic, I finished the installation process.

first_app
So after installing and configuring, you can start up your first app rather quickly.  With these commands:
rvm use ruby-1.9.3-p429  
rails new first_app
bundle update
bundle install
rails server
Bam! The server was up and running for me, viewable from a broswer and I didn't have to write a single line of code. It was almost too easy.

Github and Heroku
As recommended in the tutorial I also made a git repository, pushed the code onto github and deployed the project to heroku.  There is a lot of 'pushing' and 'pulling', and it can be a little confusing.  Here is a rundown of what's going on.

On my local machine (my laptop), I have all the source code and configuration needed to run the application.  This is good for development.  If all of your users (and other developers) had access to your laptop, this might be good enough.

But what if I want to share my code or back it up in case my machine crashes?  That's where GitHub comes along.  At the lowest level, Github is a place to back up your code.  At a higher level, it's a repository which can help you keep track of changes, allow you to easily test and revert changes,  and share and merge your changes with yourself or others.  The final thing that Github does (that I will mention) is that it helps me push my files onto Heroku.

Now, what is Heroku?  Well, for the purposes of this first app I just made, it's a better version of your laptop.  After you push your latest versions of your files onto Heroku, it figures out that you have a ruby on rails app and starts the server, where users can now visit.  You can configure heroku to work a bit differently than your laptop.  For example: (if you followed the tutorial), on your laptop you used sqlite as the backend database, but told Heroku to use another database (postgres).

Conclusion
This is the second time I made the first_app ruby on rails app.  It's been so long, it was almost all new to me.  Although, I think I was able to move along a bit faster this time, and I definitely understood a bit more than I did last time around.

No comments:

Post a Comment