SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ch.4 p103 Using ActiveRecord - Error

    Hi, I've managed to create the database (tested it using .tables and it came up fine) and entered the following, which produced an error (all displayed below)


    C:\Users\charlie\Downloads\InstantRails-2.0-win\rails_apps\shovell>ruby script/c
    onsole
    Loading development environment (Rails 2.0.2)
    >> class Story < ActiveRecord::Base; end
    => nil
    >> story = Story.new
    ActiveRecord::StatementInvalid: Could not find table 'stories'
    from C:/Users/charlie/Downloads/InstantRails-2.0-win/ruby/lib/ruby/gems/
    1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/sqlite3_adapte
    r.rb:29:in `table_structure'
    from C:/Users/charlie/Downloads/InstantRails-2.0-win/ruby/lib/ruby/gems/
    1.8/gems/activesupport-2.0.2/lib/active_support/core_ext/object/misc.rb:28:in `r
    eturning'
    from C:/Users/charlie/Downloads/InstantRails-2.0-win/ruby/lib/ruby/gems/
    1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/sqlite3_adapte
    r.rb:28:in `table_structure'
    from C:/Users/charlie/Downloads/InstantRails-2.0-win/ruby/lib/ruby/gems/
    1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/sqlite_adapter
    .rb:189:in `columns'
    from C:/Users/charlie/Downloads/InstantRails-2.0-win/ruby/lib/ruby/gems/
    1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1080:in `columns'
    from C:/Users/charlie/Downloads/InstantRails-2.0-win/ruby/lib/ruby/gems/
    1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:2363:in `attributes_from_c
    olumn_definition_without_lock'
    from C:/Users/charlie/Downloads/InstantRails-2.0-win/ruby/lib/ruby/gems/
    1.8/gems/activerecord-2.0.2/lib/active_record/locking/optimistic.rb:55:in `attri
    butes_from_column_definition'
    from C:/Users/charlie/Downloads/InstantRails-2.0-win/ruby/lib/ruby/gems/
    1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1922:in `initialize'
    from (irb):2:in `new'
    from (irb):2
    >>

    I know that someone has already posted, but they were told there was a difference between the archive and the book (the book being right) but I copied it from the book not the archive so this cannot be the issue here.

    Please help, I'm at my wits end!

    Thanks,

    Charlotte

  2. #2
    Team ********* Louis Simoneau's Avatar
    Join Date
    Sep 2009
    Location
    Melbourne, Australia
    Posts
    228
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    When you call Story.new, Rails will look at your database to determine what properties the Story object should have (based on the fields in the database). The error you're getting is Rails saying it can't find the stories table (it automatically looks for a table with the pluralized name of your model class). Have you followed the instructions on pages 101-102 re: creating a stories table in your database?

  3. #3
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds like you need to execute the migration. If your using sqlite you can use the FireFox plugin to query the database and see if the table exists. If your using mysql, you can use phpmyadmin or simply interact with mysql via command line.


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
  •