Re:How did you learn RoR?
by nostrademons on Thursday May 31, 2007 @11:35AM
(#25680)
"MVC takes a little while to wrap your brain around if you've only ever done things like PHP."
Good PHP code typically uses a MVC architecture as well. The model is the database, the controller consists of PHP files that take your $_GET and $_POST parameters and grab result sets out of the database, and the view is PHP files with no PHP tags besides your basic echoing, looping, and conditional HTML inclusion. Some people prefer to use a templating system like Smarty, which gives a prettier syntax but is conceptually the same.
Good examples are vBulletin, Phorum, and Pligg (well, the Pligg codebase has some other issues, but it's a MVC architecture). Bad examples might be stuff like PhotoPost that mashes all the code together. I highly suspect successful PHP websites like Flickr and FaceBook use a MVC architecture too, but I have no inside knowledge of their codebase.
Rails isn't that hard to learn if you've seen PHP code written like that. A Rails controller is like a collection of PHP entry pages: each method responds to a particular URL, and is responsible for populating dynamic content and rendering a template (which implicitly defaults to the method name). An ERB template is just like a PHP page, but with embedded Ruby instead of embedded PHP. An ActiveRecord object is like a PHP result set, except that changes to the object can be easily reflected back to the database. That's basically Rails in a nutshell.
Good PHP code typically uses a MVC architecture as well. The model is the database, the controller consists of PHP files that take your $_GET and $_POST parameters and grab result sets out of the database, and the view is PHP files with no PHP tags besides your basic echoing, looping, and conditional HTML inclusion. Some people prefer to use a templating system like Smarty, which gives a prettier syntax but is conceptually the same.
Good examples are vBulletin, Phorum, and Pligg (well, the Pligg codebase has some other issues, but it's a MVC architecture). Bad examples might be stuff like PhotoPost that mashes all the code together. I highly suspect successful PHP websites like Flickr and FaceBook use a MVC architecture too, but I have no inside knowledge of their codebase.
Rails isn't that hard to learn if you've seen PHP code written like that. A Rails controller is like a collection of PHP entry pages: each method responds to a particular URL, and is responsible for populating dynamic content and rendering a template (which implicitly defaults to the method name). An ERB template is just like a PHP page, but with embedded Ruby instead of embedded PHP. An ActiveRecord object is like a PHP result set, except that changes to the object can be easily reflected back to the database. That's basically Rails in a nutshell.