How Rails Saved Me Last Week
The night time, it was great. Air was cool, had just gone on a nice jog with my girlfriend, and I was quite content with everything. Being that my girlfriend has my health in my best interest, she decided to give me some cereal to take home with me. I walk out to my car in my running shorts that have no pockets and I’m half juggling my clothes, laptop case, shoes, cereal, and… my Blackberry.
def for_the_record
running_shorts != skin_tight
end
I do what I can, placing my blackberry on the roof of my car, get everything inside the car and start driving home. I get about half way there and…
Oh Crap.
I hear a horrible banging noise from the rear of my car. I look in the rear view mirror to see my Blackberry exploding in the air from its impact with the trunk of my car followed by an additional round of roughness from the black top. I spent the next little while collecting pieces from the pavement but I could not find enough to get a working device again. Despite this, what I could find on the dark road was in surprisingly good shape for the 40mph violence that had just occurred. Before I go too far off course, let me just say that the long story short is: I had insurance on the phone and I’d have a new one in a day.
That’s Not So Bad Patrick. What’s The Big Deal?
Well, for some reason, people like to call me with opportunities. These opportunities are pretty important for me to keep track of and my Blackberry was my #1 way of doing just that. That’s when I turned to rails… ah yes.
Ruby on Rails?
No. Grahm Crackers on Rails. What the heck do you think I’m talking about? You know if you’re going to act like that I’m going to just stop writing. Ok? Good. Now that we have that out of the way.
I wrote zero code to do this. That’s right. None! I used my Heroku account to create a new application. I then used their generate tool with the following command:
scaffold opportunity name:string number:string notes:text
After that I ran a rake db:migrate and it was done. Rails went, created my opportunities table, added the columns, and even made me some nice pages for me. I then went to the page and began adding stuff as I listened to voicemails. If I needed it to disappear all I had to do was close my browser window and no one was the wiser.
So You Just Made a Rails App With Two Command Line Entries?
Yes. That’s what I did. The scaffold is obviously meant to be a building block to get a project started, but the ability to generate all of this stuff absolutely blows people’s minds sometimes. It does show you though – anyone can write something in this frame work in no time. I did – with zero code. It feels almost like cheating doesn’t it? Something like that would take a bunch of code in PHP or Perl and that’s not even talking about the SQL that one would also need to do.
So that’s my answer to those of you ask me “Why do I want to learn Ruby/Rails?” I’ve now explained it in the open on the internet so hopefully I don’t have the repeat myself. Afterall, if I did, that would be violating one of the principals of the framework.
If you’ve never done anything with Rails then consider this your “Hello World!” and then go look at the files that were generated. You currently have a lot of basic stuff sitting in front of you that you can learn from. Play with it, break it, make it better, take it apart, put it back together. Worst comes to worst, you destroy your project and start over. It only took 2 command line entries to get it going.
Hey! I Want a Heroku Invite!
Well, shoot me an email, tweet, linkedin message, etc and let me know! I can definitely get you one.