What the hell is it about, in a nutshell?
I have this cheatsheet:
http://www.slash7.com/cheats/activer...cheatsheet.pdf
Is it really that simple?
| SitePoint Sponsor |




What the hell is it about, in a nutshell?
I have this cheatsheet:
http://www.slash7.com/cheats/activer...cheatsheet.pdf
Is it really that simple?
Those are the basics of it, yes, but there's a LOT more to ActiveRecord.
Check out the API documentation for ActiveRecord::Base to see just how much is in it.




Woah, that looks like a lot of reading.
In your opinion, is Ruby on Rails the easiest language to learn if you come from a design background?




Ruby is the language, Rails is a library for Ruby (Rails is written in and for Ruby).
Ruby is very easy to learn, much easier than PHP in my opinion, but I don't knwo if the language is the easiest language, but I think that it is very easy for web development. If you use PHP you program at a lower level than with Rails. This can be both an advantage and disadvantage. Rails hides a lot of the details, PHP doesn't. This makes Rails easier to understand, but it has some risks. You can safely ignore SQL (a database query language) for a while if you use Rails, because it hides the SQL for simple things. You can't if you use PHP (because it doens't hide it). If you want to do a more advanced application with Rails, you have to learn SQL.
For example:
This is Ruby code which uses activerecord, which is part of Rails. It should be easy to understand, even if you can't program. It defines that posts can be stored in a database, and that posts have comments, and belong to an author. If you want to do the same thing in PHP you get a multi-page code listing. Rails makes these things very easy.Code:class Post < ActiveRecord::Base has_many :comments belongs_to :author end
On the other hand, if you create a simple PHP script, it is one file. If you create the same simple script in Rails, you have to create a project with many files and directories (Rails creates if for you, actually). This can be confusing, because it doesn't help the simple script. If you do bigger things, this project approach does help to keep things structured.
So I think PHP is easier for very simple things, but Rails is easier for more complicated (real-world) things. Also, Ruby as a language is easier than PHP.
DISCLAIMER: I'm very biased ;-).




This argument is true, but you're comparing a framework to a language. Nothing prevents you from writing a framework for PHP that does the same thing in a comparable amount of lines (most likely not equal, since PHP doesn't support method calls in a class body, but 2 more lines should suffice).Originally Posted by Fenrir2
Not that Ruby isn't the best programming language on Earth and well-suited for trickery like this, but your comparison was so blatantly unfair that I just had to comment.




No, I'm comparing a tool to create dynamic websites websites to a tool to create dynamic websites. Many people are using PHP without a framework. Few people are using Ruby without a framework.
With a framework, the shortest would probably be this:
Or you could do this:Code:execute_ruby("class Post < ActiveRecord::Base has_many :comments belongs_to :author end");
But unfortunately, I don't know a working framework that lets you do that.Code:class Post extends ActiveRecord_Base { function __construct() { $this->addAssociation('has_many', 'comments'); $this->addAssociation('belongs_to', 'author'); } }
Note that you could do this:
But that seems very wrong...Code:class Post extends ActiveRecord_Base { $associations = array( array('has_many', 'comments'), array('belongs_to', 'author')); }
Bookmarks