• Creating a directory in Ruby

    Now let's try to create a directory.

     

    We will use script/generate to generate the model, controller and views for the directory.

     

    <code>$>ruby script/generate scaffold_resource article title:string body_format:string body:text</code>

     

     

    I will not include the source code in the text, so as not to bloat the article, it can be viewed online, I will describe what different pieces of code are for.

     

    Ruby-on-Rails generated several files, let's look at some of them:

     

    app/models/article.rb - article model

    app/controllers/articles\_controller.rb - controller for managing the articles catalog

    config/routes.rb - added line map.resources :articles

    app/views/articles/... - views for creating, editing and viewing articles

    app/views/layouts/articles.rhtml - page template for working with the catalog

    db/migrate/001_create_articles.rb - create a table for articles in the database


    Tags Tags : , , ,