SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Chapter 8 Rake problem

    I'm new at this so I'm hoping one of you can point me in the right direction to troubleshoot this problem. On page 240, I get an error running the "rake db:migrate" command. As you can see from the trace below,

    You have a nil object when you didn't expect it!
    You might have expected an instance of Array.
    The error occurred while evaluating nil.first


    the error seems to be a missing element. How should I go about finding what array is missing, assuming that's the problem?

    Thanks for the help.


    Full Trace

    [ahale@s1bwayapp1 shovell]$ rake db:migrate --trace
    (in /home/ahale/shovell)
    ** Invoke db:migrate (first_time)
    ** Invoke environment (first_time)
    ** Execute environment
    ** Execute db:migrate
    rake aborted!
    You have a nil object when you didn't expect it!
    You might have expected an instance of Array.
    The error occurred while evaluating nil.first
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:360:in `migration_files'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/mysql_adapter.rb:248:in `sort_by'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:359:in `each'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:359:in `sort_by'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:359:in `migration_files'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:342:in `migration_classes'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:330:in `migrate'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:297:in `up'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/migration.rb:288:in `migrate'
    /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/databases.rake:4
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `call'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `each'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invoke'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `synchronize'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `top_level'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `each'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `top_level'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in `standard_exception_handling'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:in `top_level'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1711:in `run'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in `standard_exception_handling'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in `run'
    /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.3/bin/rake:7
    /usr/local/bin/rake:16:in `load'
    /usr/local/bin/rake:16


    Versions

    [ahale@s1bwayapp1 shovell]$ ruby script/about
    About your application's environment
    Ruby version 1.8.6 (i686-linux)
    RubyGems version 0.9.1
    Rails version 1.2.3
    Active Record version 1.15.3
    Action Pack version 1.13.3
    Action Web Service version 1.2.3
    Action Mailer version 1.3.3
    Active Support version 1.4.2
    Application root /home/ahale/shovell
    Environment development
    Database adapter mysql
    Database schema version 3

  2. #2
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First thing I always do in this project is reverse my steps to a place where I know it worked. Somewhere in that margin there may be a code error. Try using the code download from the site and compare.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2004
    Location
    USA
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe an error in your migration file itself. Maybe post that code too.
    Also want to make sure rails can connect to the db.

  4. #4
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I also have this problem. Here's what I get within Rails 1.2.3

    rake aborted!
    uninitialized constant AddPermalinkTo

    The last time the code passed was at the end of Chapter 07 and that was because other posters in this forum helped me with the created_at function that is different than the book.

    I believe I'm able to connect to the db because rails sees that other tables are already generated:

    exists app/models/
    exists test/unit/
    exists test/fixtures/
    create app/models/user.rb
    create test/unit/user_test.rb
    create test/fixtures/users.yml
    exists db/migrate
    create db/migrate/004_create_users.rb
    Slim:~/cardy/cardy sam$ rake db:migrate
    (in /Users/sam/cardy/cardy)
    rake aborted!
    uninitialized constant AddPermalinkTo

    So it appears that the fixed code at the end of chapter 07 may be contributing to it?

    WIll check the errata next, thanx, sam

  5. #5
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't know if this is your issue, just taking a swing in the dark, but a migration's filename needs to match its class name,

    For example, 004_create_users.rb should contain class CreateUsers < ActiveRecord::Migration
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  6. #6
    SitePoint Member
    Join Date
    Jun 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After reading your msg, Sam, I double checked the file and it sure does contain that string as the first line. It also matches the code archive provided.

    The errata does not indicate this particular piece of code.

    So for me, I'm unsure where the AddPermalinkTo could be a problem, sam

  7. #7
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just musing, AddPermalinkTo is a kind of funny migration name ... I'd expect something like AddPermalinkToArticles or something like that.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?


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
  •