SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Chapter 7 Page 189 problem

    Hi--

    I've run into a persistent problem on page 189.

    I'm running InstantRails on Windows XP. When I run InstantRails, I first go into the console to turn on the server. Here are the commands:

    Code:
    C:\INSTAN~1\INSTAN~1>CD C:\InstantRails\InstantRails
    
    C:\InstantRails\InstantRails>PATH C:\InstantRails\InstantRails\ruby\bin;C:\Insta
    ntRails\InstantRails\mysql\bin;c:\ruby\bin;C:\Python25;C:\Program Files\QuickTim
    e\QTSystem\;;C:\INSTAN~1\INSTAN~1\ruby\bin;C:\INSTAN~1\INSTAN~1\Apache;C:\INSTAN
    ~1\INSTAN~1\PHP
    
    C:\InstantRails\InstantRails>cd rails_apps
    
    C:\InstantRails\InstantRails\rails_apps>dir
     Volume in drive C has no label.
     Volume Serial Number is 6869-992D
    
     Directory of C:\InstantRails\InstantRails\rails_apps
    
    03/02/2007  07:41 PM    <DIR>          .
    03/02/2007  07:41 PM    <DIR>          ..
    02/16/2007  08:45 PM    <DIR>          cookbook
    03/02/2007  07:41 PM    <DIR>          shovell
    02/16/2007  08:46 PM    <DIR>          typo-2.6.0
                   0 File(s)              0 bytes
                   5 Dir(s)     298,647,552 bytes free
    
    C:\InstantRails\InstantRails\rails_apps>cd shovell
    
    C:\InstantRails\InstantRails\rails_apps\shovell>ruby script/server
    => Booting Mongrel (use 'script/server webrick' to force WEBrick)
    => Rails application starting on http://0.0.0.0:3000
    => Call with -d to detach
    => Ctrl-C to shutdown server
    Running Mongrel server in development mode at 0.0.0.0:3000
    After this is done, I then open up another window to enter the "s = Story.find :first" command. However, that has never worked for me. Here are the commands and feedback.

    Code:
    C:\INSTAN~1\INSTAN~1>CD C:\InstantRails\InstantRails
    
    C:\InstantRails\InstantRails>PATH C:\InstantRails\InstantRails\ruby\bin;C:\Insta
    ntRails\InstantRails\mysql\bin;c:\ruby\bin;C:\Python25;C:\Program Files\QuickTim
    e\QTSystem\;;C:\INSTAN~1\INSTAN~1\ruby\bin;C:\INSTAN~1\INSTAN~1\Apache;C:\INSTAN
    ~1\INSTAN~1\PHP
    
    C:\InstantRails\InstantRails>cd rails_apps
    
    C:\InstantRails\InstantRails\rails_apps>dir
     Volume in drive C has no label.
     Volume Serial Number is 6869-992D
    
     Directory of C:\InstantRails\InstantRails\rails_apps
    
    03/02/2007  07:41 PM    <DIR>          .
    03/02/2007  07:41 PM    <DIR>          ..
    02/16/2007  08:45 PM    <DIR>          cookbook
    03/02/2007  07:41 PM    <DIR>          shovell
    02/16/2007  08:46 PM    <DIR>          typo-2.6.0
                   0 File(s)              0 bytes
                   5 Dir(s)     298,446,848 bytes free
    
    C:\InstantRails\InstantRails\rails_apps>cd shovell
    
    C:\InstantRails\InstantRails\rails_apps\shovell>s = Story.find :first
    's' is not recognized as an internal or external command,
    operable program or batch file.
    
    C:\InstantRails\InstantRails\rails_apps\shovell>
    Can anyone tell me what is wrong, and what I can do to resolve the problem?

    Thank you.

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this from 'rails_apps\shovell' before entering ruby commands:

    ruby script/console

    your ruby commands were going to the command prompt rather than the ruby console.

  3. #3
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    It worked; now getting nil object

    That worked; thank you. I had been typing "ruby script/server" into the window so much that I didn't see that I should start by entering "ruby script/console" into the terminal.

    Now I'm getting "NoMethodError". What does this mean? Here is how it reads:
    "NoMethodError:You have a nil object when you didn't expect it!"

    Thanks in advance.

    Paul

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're welcome, glad i could help (its a rare thing for me! lol)

    Hmm... now that's a good question. This is happening when you enter "s = Story.find :first"? If so, did the 'find' method work for you when it was introduced back on page 129?

    The NoMethodError makes me think there may be a typo or something in your model or database, or you might be using a version of ActiveRecord that doesn't support "find". Then again, my experience with ruby and rails is very limited... perhaps a more knowledgeable community member will chime in with the voice of experience.

  5. #5
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, everything on page 129 worked fine for me.

    I tried to copy the commands but since I was in the Ruby development environment after firing up the Ruby console, that didn't work.

    So, I made a screenshot and uploaded that here.

    If anyone can help, that would be deeply appreciated.

    And thanks for your help.

    Paul

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh, so we're not talking about the find method. Could you paste the code from your story and vote models? (story.rb & vote.rb) The .vote method will not be available if ActiveRecord does not find a relation defined between the two models.

  7. #7
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Story.rb and vote.rb

    Here is the code for story.rb

    Code:
    class Story < ActiveRecord::Base
          validates_presence_of :name, :link
          has_many :votes
    end
    Here is the code for vote.rb

    Code:
    class Vote < ActiveRecord::Base
    end
    Thank you very much.

  8. #8
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,033
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    It looks to me like the error occured when it was trying to access the votes that s should have. I've found a few errors occur if ruby and rails try to count nil items.

    Open your database and make sure that you have at least one story and that it has at least one vote.

    Good luck,
    Andrew
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  9. #9
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Vote should also belong_to :story I believe.

  10. #10
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vgarcia View Post
    Vote should also belong_to :story I believe.
    Hheheh... he'll get to that on page 191. (;


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
  •