SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Build Your Own Ruby on Rails - CHAP 9

    I'm in Chapter 9, working through the process, and have gotten stuck on page 289. When I try viewing my shovell site, I now get this:

    NoMethodError in Story#index

    Showing story/index.rhtml where line #2 raised:

    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.size

    Extracted source (around line #2):

    1: <h2>
    2: <%= "Showing #{ pluralize(@stories.size, 'story') }" %>
    3: </h2>
    4: <%= render artial => 'story', :collection => @stories %>

    RAILS_ROOT: C:/InstantRails-2.0/InstantRails-2.0-win/rails_apps/shovell

    I've checked my index.rhtml file and it's exactly as what is in the book and the archives, so I'm not sure what the problem is. If you have any guidance, I would greatly appreciate it! Thank you!

    Jamen McGranahan

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hm, one thing I can think of off hand is that you haven't applied the rake migration yet for the creation of the vote_counts column, as that's what the variable is referencing to.

  3. #3
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, I have ran the rake migration for the votes column and have checked my MySQL database to verify the existence of the column. I'm hesitant to proceed with the book until I can get this issue resolved. Any other ideas?

    Jamen

  4. #4
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jmcgranahan View Post
    Actually, I have ran the rake migration for the votes column and have checked my MySQL database to verify the existence of the column. I'm hesitant to proceed with the book until I can get this issue resolved. Any other ideas?

    Jamen
    Is it possible to attach a zip file of your current code so that we may look at it? It might be hard to back and forth on this without seeing the full code source.

  5. #5
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I got it. It appears I was missing one single comma from my code. :-( Gee... I'm now completing the test suite on chapter 9 (am running the rake test command currently).

    Jamen

  6. #6
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jmcgranahan View Post
    I think I got it. It appears I was missing one single comma from my code. :-( Gee... I'm now completing the test suite on chapter 9 (am running the rake test command currently).
    Ah, yeah, this happens to the best of us. Missing commas/semi-colons will be your mortal enemy. Good to see that it got figured out though, and good luck with the rest of the book.

  7. #7
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Tests error

    Well, we are making progress, but now my functional tests in chapter 9 are failing. I'm getting this:

    1) Failure:
    test_should_use_story_index_as_default(StoryControllerTest)
    [./test/functional/story_controller_test.rb:112:in `test_should_use_story_in
    dex_as_default'
    C:/InstantRails-2.0/InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/active
    support-2.0.2/lib/active_support/testing/default.rb:7:in `run']:
    The generated path <"/story"> did not match <"/">

    Here is what I have in story_controller_test.rb:
    def test_should_use_story_index_as_default
    assert_routing '', :controller => 'story', :action => 'index'
    end

    And here is what I have in routes.rb:
    ActionController::Routing::Routes.draw do |map|
    map.connect ':controller/service.wsdl', :action => 'wsdl'
    map.story 'story/show/ermalink',
    :controller => 'story',
    :action => 'show'
    map.connect ':controller/:action/:id'
    map.connect '', :controller => "story"

    It would seem that it "should" work - but should is the operative word. There must be something I am missing. Ideas (again)?

    Jamen

  8. #8
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Solved my own problem. I needed to move this line to the top of routes.rb:

    map.connect '', :controller => "story"

    Once I did that, my tests passed.

    Jamen

  9. #9
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jmcgranahan View Post
    Solved my own problem. I needed to move this line to the top of routes.rb:

    map.connect '', :controller => "story"

    Once I did that, my tests passed.

    Jamen
    Sorry, got caught up with work and didn't respond in a reasonable amount of time Good to hear that the issue was solved


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
  •