views:

2738

answers:

10

I'm a PHP developer who knows a little bit of Ruby. I want to learn Ruby on Rails, but most of the resources I've come across treat RoR functionality as "magic" -- i.e., it has a certain internal consistency, but don't bother asking how it works in terms of Ruby, MySQL, etc.

Anyway, I want a deep understanding of how RoR works, the design decisions that went into building it, etc. In particular I'm interested in ActiveRecord, but really I'm looking for the whole package.

Any books / sites / advice welcome.

+4  A: 

I found this site a good starting reference:

http://www.tutorialspoint.com/ruby-on-rails-2.1/index.htm

It assumes MySQL in its examples.

I am sure you can find heaps and heaps by just googling for "ruby on rails tutorials", though.

Mark
+10  A: 

The books "Agile Web Development with Rails" and "The Rails Way" are both pretty good. "Pro Active Record" goes really in depth for Active Record, but doesn't touch on too much else. The podcast Railscasts sometimes just uses the magic, but sometimes it explains what is really going on. Various blogs such as Art of Mission can get into what your looking for.

Additionally, using the ruby-debug gem gives you a much better understanding of what is going on - you can step into what is running behind the scenes.

DA
I would second the Agile Web Development with Rails book.
tvanfosson
+3  A: 

This is sort of a tangential answer to your question, but I, too, came from PHP development over to Ruby/Rails dev, and it was a big transition for me. As PHP devs, we're used to getting into the nitty-gritty, to to speak, and not being prevented from looking under the hood.

By design, Rails is a black box. You're supposed to learn Rails, almost as a language itself. It's a new way of thinking of web dev, especially from a PHP dev's perspective, though this idea is not uncommon to programming in general.

Not bothering to look under the hood may be the best way to start doing things "the Rails way."

Lucas Oman
I disagree about Rails being a black box. It's open source, and I often look into pieces to figure out why some weird behavior I'm not expecting is going on. Additionally, if you look around a bit, many people are patching various pieces in their blogs, and some of those even get accepted to core.
DA
Coming from PHP, Ruby and Rails can seem like a whole different world. If you have experience with CodeIgniter, Cake or Kohana it will make Rails easier to grok. Ruby itself is straightforward and elegant once you stop trying to use it as you would PHP :)
robsymonds
It's very easy to get under the hood, just open the source, it's an interpreted language, all the source you need is right there on your computer you just have to read it. I disagree with this.
railsninja
@railsninja Of course I understand that RoR is open-source and an interpreted language. My point is that it does a lot of "magic", and going under the hood to understand its ins and outs is not reasonable for someone trying to get a project done. So RoR is as good as a black box.
Lucas Oman
+5  A: 

If you really want to know how it works, you can just look at the source code. The online API docs let you see the source code of every method right in the documentation page.

ActiveRecord in Rails is based on Martin Fowler's Active Record pattern. It's basically an ORM (object-relational mapper). It's not even really that sophisticated as far as ORMs go. Java Persistence with Hibernate has a good overview of common ORM concepts

Ken Liu
+2  A: 

Jamis Buck has a nice series of "Under the Hood" articles on his blog that cover some aspects of Rails' internals.

John Topley
+6  A: 

There are two areas here that can be examined separately:

  1. General concepts (which include design patterns, general attitude principles like DRY and CoC or even agility etc.) since they are the principles behind many design decisions in Rails. Any of these concepts can be studied independently of Rails (since they are general programming concepts). It's good to have at least some understanding of these before digging any deeper. There are many sources about such general principles all over the net (aforementioned Martin Fowler's site is one of the better sources for grasping such concepts).

  2. The way Rails implements these concepts into its corpus. There are, again, two things to have in mind here. Since Rails heavily exploits features of its mother language, it's crucial to understand Ruby's peculiarities (such as mixins and plenty of Ruby's dynamic features). The last thing to understand is how Rails uses these features, ie. how it's broken down into classes and modules, how many of its features are dynamically created on the run and so on. For this purpose, I highly recommend book Ruby for Rails from David A. Black (which is exactly about Ruby, its peculiarities and the way Rails uses them). While this book might be a bit out of date, I think it's still invaluable in its content.

Milan Novota
A: 

ruby metaprogramming magic in rails: look at books by Rappin "Professional Rails" and Ediger "Advanced Rails", in addition to Black "Ruby for Rails" mentioned above

Naming conventions are important:

http://rails.wincent.com/wiki/Rails_conventions

http://www.softiesonrails.com/2007/10/18/ruby-101-naming-conventions

Gene T
+1  A: 

The "magic" in Rails involves method_missing and the concept of metaprogramming. Dave Thomas of The Pragmatic Programmers created a set of screencasts on metaprogramming Ruby.

PHP has a somewhat-equivalent function called __call, and PHP 5.3 introduced __callstatic. You might take a look at those, as well as search Google for "php metaprogramming", for some reading material on implementing Rails-like behavior in PHP.

Ryan Riley
+5  A: 

This one might fit here well too -> http://railsforphp.com/

A: 

If you really want to understand Rails, read the source for the bit of Rails that you want.

/Library/Ruby/Gems/1.8/gems/ on OSX or freeze rails and have access to it in your RAILS_ROOT/vendor/ directory

Omar Qureshi