What I liked about Ruby on Rails

    To begin with, I am a PHP programmer with good experience. A lot of interesting things were written, there were large projects, telecommunication services covering almost the whole of Europe. Development and support of projects was carried out not a month or two, but a year and a half.

    After moving to a managerial position and avoiding the need to constantly program, it became possible to devote more time to studying and comparing new languages ​​and technologies. In principle, this is part of my work :)

    Look fell on Ruby he Rails. The famous Agile Web Development with Rails: Second Edition was read.and a small project is written. Here I will try to list the features of this beautiful framework that I liked. If you do not plan to write on rails, then I think it will still be interesting for you to get acquainted with some goodies that can be easily ported to other languages ​​(a lot has already been done for PHP, including me).

    Application framework (a matter of taste)
    Yes. Although many will shout that this is a restriction of their freedom, but as my experience shows, many programmers simply need to be limited. The structure of rails is very logical. Each component has its own place. Very clear separation of MVC components.

    Application Configuration (Convenient)
    By following the basic rules for naming application components, you avoid tedious configuration. The initial division into runtimes: development, test and production is also a good tone in programming.

    Database version control (necessary in large projects)
    Database migration. All the changes you make to the database: creating tables, adding indexes, etc. - are placed in the application code and stored in your version control system (I have SVN). Each migration looks something like this

    class AddEmailColumnToOrders <ActiveRecord :: Migration
    def self.up
    add_column: orders,: e_mail,: string
    end

    def self.down
    remove_column: orders,: e_mail
    end
    end

    Successful Active Record(powerful library) The
    simplicity of creating models for working with database objects is amazing.

    class Order <ActiveRecord :: Base
    end

    This is enough to work with the orders table. No explicit mapping. Very conveniently and flexibly implemented relationships between entities.

    Testing (necessary in large projects)
    There are only emotions. There are three types of tests:
    1. unit model tests - a la JUnit, PHPUnit (this is familiar),
    2. functional tests - the same unit tests, but for controllers,
    3. integration (?) Tests of entire scripts of a web application; the code says it all

    def test_buying_a_product
    dave = regular_user
    dave.get "/ store / index"
    dave.is_viewing "index"
    dave.buys_a @ruby_book
    dave.has_a_cart_containing @ruby_book
    dave.checks_out DAVES_DETAILS
    dave.is_viewing "index"
    check_for_order DAVES_DETAILS, @ruby_book
    end

    This is a test of the application at the highest level.

    Caching (necessary in large projects)
    Here I liked 2 things. The first is page caching. Suppose by url / products / details / 1 you display a description of the goods. Rails can create the /products/detail/1.html file in the public directory, which will be given by the web server as static content. It’s clear that this will have a great effect on performance.
    The second thing is the observers of models in which you determine when to clear the cache. For instance,

    class ArticleSweeper <ActionController :: Caching :: Sweeper
    observe Article
    # If we create a new article, the public list of articles must be regenerated
    def after_create (article)
    expire_public_page
    end
    # If we update an existing article, the cached version of that article is stale
    def after_update (article)
    expire_article_page (article.id)
    end
    # Deleting a page means we update the public list and blow away the cached article
    def after_destroy (article)
    expire_public_page
    expire_article_page (article.id)
    end
    end

    Javascript (convenient)
    1. good integration with prototype,
    2. a wide selection of helpers for developing ajax application components;
    3. generation of javascript using RJS templates (this is a type of representation from MVC); it looks something like this

    page.replace_html ("cart",: partial => "cart" ,: object => cart )
    page [: current_item] .visual_effect: highlight,: startcolor => "# 88ff88",: endcolor => "# 114411 "

    3. if your application is rich in javascript, and the client is off (there are still smart people), then it's easy enough to still leave them the opportunity to work with your site.

    Readable URLs (conveniently) The
    implementation of recognition and generation of friendly URLs is simple and logical.

    map.connect 'store / checkout',: conditions => {: method =>: get}
    ,: controller => "store" ,: action => "display_checkout_form" map.connect 'store / checkout',: conditions => {: method =>: post} ,: controller => «store»,: action => «save_checkout_form»

    Advanced.
    Debugging and other (convenient)
    Built-in scripts profiler and benchmark. The breakpoint method, called in the controller interface, terminates the page script, allows you to perform any actions with the application through the console, and then continue to execute the script.

    This is a little that I can remember at 11 o’clock in the evening. It is forbidden to start holivars. I just listed what I would like to see in all projects.

    Also popular now: