SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: ActiveRecord

  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Port Sunlight
    Posts
    815
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ActiveRecord

    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?

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    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.

  3. #3
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Port Sunlight
    Posts
    815
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  4. #4
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:

    Code:
    class Post < ActiveRecord::Base
      has_many :comments
      belongs_to :author
    end
    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.

    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 ;-).

  5. #5
    SitePoint Guru
    Join Date
    May 2005
    Location
    Finland
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Fenrir2
    If you want to do the same thing in PHP you get a multi-page code listing. Rails makes these things very easy.
    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).

    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.

  6. #6
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:

    Code:
    execute_ruby("class Post < ActiveRecord::Base
      has_many :comments
      belongs_to :author
    end");
    Or you could do this:

    Code:
    class Post extends ActiveRecord_Base
    {
      function __construct()
      {
        $this->addAssociation('has_many', 'comments');
        $this->addAssociation('belongs_to', 'author');
      }
    }
    But unfortunately, I don't know a working framework that lets you do that.

    Note that you could do this:

    Code:
    class Post extends ActiveRecord_Base
    {
      $associations = array(
         array('has_many', 'comments'),
         array('belongs_to', 'author'));
    }
    But that seems very wrong...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •