Women in Technology

Hear us Roar



Article:
  Rolling with Ruby on Rails Revisited
Subject:   rewriting "Rolling with Ruby on Rails Revisited" to reflect reality of Rails 2.0
Date:   2008-02-13 11:28:08
From:   teresa3
I have been going through this tutorial because I believe it is effective in exemplifying the power of the technology. Two questions I have for the
group:


I have been trying to rewrite the tutorial so that it might be helpful for those who have Rails
2.0. I have since come to the conclusion that one need not manually import the data model into MySQL, because Rails 2.0 can do that now, such that:




in rails becomes in SQL
foo:string foo varchar(255)
bar:text bar text
baz:integer baz int



  1. how does one express the following SQL statement as a rails statement:


    constraint fk_recipes_categories foreign key (category_id) references
    categories(id);



  2. In part two of the tutorial:


    http://www.onlamp.com/pub/a/onlamp/2007/01/05/revisiting-ruby-on-rail...


    I thought that perhaps one could connect Recipe to Category by adding the
    following to the appropriate Rails 2.0 data model creation statements:


    has_many :recipes

    belongs_to :category


    When that didn't work, I added the two statements to the category & recipe
    model files, as instructed by the tutorial, to no avail. Are these two
    statements even pertinent when using Rails 2.0 to create our data model such
    that one can easily create Categories and assign Recipes to Categories ?
Full Threads Newest First

Showing messages 1 through 1 of 1.

  • rewriting "Rolling with Ruby on Rails Revisited" to reflect reality of Rails 2.0
    2008-02-19 04:35:05  Bill Walton | [View]

    Hi Teresa,

    My original intent with this tutorial was to show first the creation of the database via 'standard' techniques and, then, the much easier 'Rails way.' I covered migrations in the third article in the series. It's not yet clear to me how, in the updated version of this tutorial. to clearly show the correllation between the SQL script and Rails migrations. They're there, though, and I'll be working on it.

    In the meantime, the change required in Rails 2.x is use the .references keyword in the migration. The :has_many and :belongs_to associations are still required in the models.

    Hope that helps,
    Bill