I finally gave in. I’ve been hearing about how Ruby on Rails is the greatest thing since sliced bread for a few years now. I refused to learn it because I figured that it was just a developer fad that would descend into obscurity soon enough. After all, I had never heard of Ruby before.
I don’t know what triggered it. Perhaps it is because I was tired of relearning symfony every time I started a new project after a break. The documentation is extensive, which is great, but one of the downfalls of extensive documentation is that it takes forever to read enough of it to learn your way around.
Further, much of the documentation is outdated. Much of what is says about forms, for instance, does not apply anymore. The only way to learn the new forms API is to read the very incomplete forms book.
Then, they moved to Doctrine. Well, they wanted to replace the Propel ORM with Doctrine eventually. Therefore, I thought it was smart to switch over to Doctrine. Unfortunately, almost all of the documentation still refers to Propel. Also, very few plugins implement Doctrine, severely limiting your choices.
So, when I wanted to start a new project recently, all of these factors together made me rethink using symfony. I should note I’ve not used it for a few months, so it may have changed, but I wasn’t much in the mood to go through all of the documentation again to find out.
Using PHP without a framework was out of the question. It just made things much faster, and I knew that if I didn’t use one, I’d be virtually making my own, which would take a lot longer.
I have been through several frameworks. Besides symfony, I’ve also used CakePHP, and Prado. I’d heard enough about the Zend Framework that I was pretty sure I didn’t want to use it.
A thought arose: what about Ruby on Rails? I have my own server now in preparation for the new project, so I could really install anything I wanted. I wasn’t entirely sure, though, so I searched a bit about why RoR is so hyped.
I found a few things, but nothing significant. I did stumble upon a book called why’s (poignant) guide to ruby. I told myself I’d read it if I found a good reason to learn Ruby.
I ended up reading the first chapter or two, and the book was so funny that I couldn’t stop reading, so I continued and finished reading it the next day.
Of course, it only taught Ruby, not Rails. However, I really liked the syntax of Ruby, though it was a bit alien to me. Never before had I seen anything even remotely similar to:
[1,2,3,4].each { |number| puts number }I mean, you can guess what’s going on, and you’d probably be right, but it is so different from what I’m used to that it was a bit weird. I liked it, though.
So, then I tried to see how I could learn Rails. Luckily, I found the book Simply Rails 2 at SitePoint. Also luckily, they had a PDF version of it, so that I could read it. With a final stroke of luck, it was cheaper than the hardcopy.
As if my luck would not end, I got sick this week. OK, no I don’t like being sick. But it got so bad that I came home yesterday. That means that between sleeping and feeling relatively terrible, well, I can read this book.
Before I wrote this post, I just finished chapter 6. It is covering a lot, so I’m taking a break so as to not forget everything.
It is funny, because each time a new topic is introduced, I am certain it will be complicated and will be hard to understand. Then it turns out to only take a few simple lines.
As I proceed, I see where the PHP copies of Rails got their ideas, but also where they went wrong. Almost everything you can do in those frameworks, which seem great by themselves, are even better and easier in Rails.
For instance, I remember in CakePHP that to create associations, you had to create a large array of them in the model. However, in Rails it is simply something like:
class Author < ActiveRecord::Base
has_many :books
endEven the testing is simpler than anything you could dream of in PHP. Here’s an example (modified a bit) of a unit test from the book:
test "should not be valid without name" do
# Try to create a story without a name
s = Story.create :name => nil,
:link => 'http://www.example.com'
# Assert that the name field has errors
assert s.errors.on :name
endAnd a functional test:
test "should show index" do
get :index
# Test that the HTTP response is 200
assert_response :success
assert_template 'index'
# The instance variable @story is not nil
assert_not_nil assigns :story
endSo yes, I’m learning Rails. I’ll probably post in the future about how I set up my environment both on my local computer and remote server.
Similar Posts:
- Some of the Reasons I Love Programming in Ruby
- Learning Vim and Loving It
- Researching for the Game
- Twitter Updates for 2009-04-20
- Angels and Demons
If you enjoyed this post, make sure you subscribe to my RSS feed!
Tags: CakePHP, Doctrine, Prado, Propel, Rails, Ruby, Ruby on Rails, Simply Rails 2, SitePoint, symfony






































[...] Blog of the Perpetual Seeker « Hopping on to the Rails [...]