SitePoint Sponsor

User Tag List

Results 1 to 22 of 22
  1. #1
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simply Rails problem on page 207

    Sorry, I posted this on Questions, then realized I should have posted it here. I started this forum today.

    I am new to Rails.
    When I browse to localhost:3000/stories, —it works.
    When I browse to localhost:3000/stories/2
    I get a NoMethodError showing stories/show.html.erb that says "You have a nil object when you didn't expect it! The error occured while evaluating nil.name"

    The Extracted Source is
    1: <h2><%= @story.name %></h2>
    2: <p><%= link_to @story.link, @story.link %></p>

    (which is from show.html.erb)

    stories_controller.rb shows
    class StoriesController < ApplicationController

    def index
    @story = Story.find(:first, :order => 'RANDOM()')
    end

    def new
    @story = Story.new
    end

    def create
    @story = Story.new(params[:story])
    if @story.save
    flash[:notice] = "Story submission succeeded"
    redirect_to stories_path
    else
    render :action => 'new'
    end

    def show
    @story = Story.find(params[:id])
    end
    end
    end

    Can anyone help?

    Thanks

  2. #2
    SitePoint Addict ruby-lang's Avatar
    Join Date
    Aug 2007
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello, and welcome to the forum.

    You probably figured out part of what's happening, but let me recap what Rails is doing step by step. When you go to localhost:3000/stories/2, the show method is called. To populate the @story instance variable, it calls Story.find, which returns a Story object if it finds one row in the database with the id you are passing, in this case 2. Now, there's no row with an id = 2 in your stories table, so find returns nil to indicate it didn't find anything.

    After show returns, Rails calls the corresponding template, stories/show.html.erb. But @story isn't a Story object, it is nil, and nil doesn't have properties like name and link. That's why you see that error. One way you can prevent that from happening is adding a check to the show template like this:
    Code:
    <% if @story %>
      <h2><%= @story.name %></h2>
      <p><%= link_to @story.link, @story.link %></p>
    <% else %>
     <p>No story found.</p>
    <% end %>

  3. #3
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I look in the SQLite Database Browser, I find that I have in row 1:
    id: 2
    name: Sitepoint Forums
    link--etc.

    I also have put 4 more id's in the stories table.

    So, why does localhost:3000/stories/2 return an error?

    Please be patient, I am not a programmer.

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the whole of show.html.erb.

    When posting to this forum, if you surround the code you post with a [code] block (or highlight it all and use # on the toolbar), the code will be displayed correctly formatted here.
    Code:
    #Like this
    def some_method
      a = b
    end

  5. #5
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you. Here is the code for show.html.erb:
    Code:
    <h2><%= @story.name %></h2>
    <p><%= link_to @story.link, @story.link %></p>

  6. #6
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think that should generate an error. The coding is right, so the problem must be elsewhere.

    Are you looking at the right SQLite database. Don't forget that if you are looking at the development version of your app, the database will be called something like:

    app_name_development

    and when you run in production mode the system uses a different database called something like

    app_name_production

    Unless you have rewritten the database.yml to have both production and development environments pointing at the same database.

  7. #7
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your help.
    It seems to me that the database.yml is pointing correctly. Would you examine the code?
    Code:
    # SQLite version 3.x
    #   gem install sqlite3-ruby (not necessary on OS X Leopard)
    development:
      adapter: sqlite3
      database: db/development.sqlite3
      timeout: 5000
    
    # Warning: The database defined as 'test' will be erased and
    # re-generated from your development database when you run 'rake'.
    # Do not set this db to the same as development or production.
    test:
      adapter: sqlite3
      database: db/test.sqlite3
      timeout: 5000
    
    production:
      adapter: sqlite3
      database: db/production.sqlite3
      timeout: 5000

  8. #8
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webmathetic View Post
    When I look in the SQLite Database Browser, I find that I have in row 1:
    id: 2
    name: Sitepoint Forums
    link--etc.

    I also have put 4 more id's in the stories table.

    So, why does localhost:3000/stories/2 return an error?

    Please be patient, I am not a programmer.
    Assuming that, as you are looking at localhost:3000, this is a development view (you haven't specifically told the mongrel or webrick to use product mode):

    When you use SQLite Database Browser, are you sure you are looking at the development.sqlite3 database?

  9. #9
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the path to my database, as shown in SQLite Database Browser:
    Code:
    C:\InstantRails\rails_apps\shovell\db\development.sqlite3
    Of course, this is Windows. The book suggested that I put the InstantRails folder in the C drive.

  10. #10
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That all looks fine.

    What is the error you get?

  11. #11
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
     NoMethodError in Stories#show
    
    Showing stories/show.html.erb where line #1 raised:
    
    You have a nil object when you didn't expect it!
    The error occurred while evaluating nil.name
    
    Extracted source (around line #1):
    
    1: <h2><%= @story.name %></h2>
    2: <p><%= link_to @story.link, @story.link %></p>
    
    RAILS_ROOT: C:/InstantRails/rails_apps/shovell
    Application Trace | Framework Trace | Full Trace
    
    app/views/stories/show.html.erb:1:in `_run_erb_47app47views47stories47show46html46erb'
    
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/base.rb:637:in `send'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/base.rb:637:in `compile_and_render_template'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/base.rb:365:in `render_template'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/base.rb:316:in `render_file'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1100:in `render_for_file'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:836:in `render_with_no_layout'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/layout.rb:262:in `render_without_benchmark'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:51:in `render'
    C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:51:in `render'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1153:in `default_render'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1164:in `perform_action_without_filters'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform_action_without_caching'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:678:in `perform_action'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/query_cache.rb:8:in `cache'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:in `perform_action'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `send'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `process_without_filters'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:685:in `process_without_session_management_support'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:123:in `process'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:388:in `process'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in `handle_request'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in `dispatch'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in `dispatch'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:76:in `process'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:74:in `synchronize'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:74:in `process'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:159:in `process_client'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in `each'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in `process_client'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `initialize'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `new'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in `initialize'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in `new'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:282:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:281:in `each'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:281:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:128:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/command.rb:212:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:281
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64
    C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
    C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
    C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
    C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
    script/server:3
    
    app/views/stories/show.html.erb:1:in `_run_erb_47app47views47stories47show46html46erb'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/base.rb:637:in `send'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/base.rb:637:in `compile_and_render_template'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/base.rb:365:in `render_template'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_view/base.rb:316:in `render_file'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1100:in `render_for_file'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:836:in `render_with_no_layout'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/layout.rb:262:in `render_without_benchmark'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:51:in `render'
    C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:51:in `render'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1153:in `default_render'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1164:in `perform_action_without_filters'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform_action_without_caching'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:678:in `perform_action'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/query_cache.rb:8:in `cache'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:in `perform_action'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `send'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in `process_without_filters'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:685:in `process_without_session_management_support'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:123:in `process'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:388:in `process'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in `handle_request'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in `dispatch'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in `dispatch'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:76:in `process'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:74:in `synchronize'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/rails.rb:74:in `process'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:159:in `process_client'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in `each'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:158:in `process_client'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `initialize'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `new'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:285:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in `initialize'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in `new'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel.rb:268:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:282:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:281:in `each'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:281:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:128:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/command.rb:212:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:281
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64
    C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
    C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
    C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
    C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
    script/server:3
    
    Request
    
    Parameters:
    
    {"id"=>"2"}
    
    Show session dump
    
    --- 
    flash: !map:ActionController::Flash::FlashHash {}
    
    
    Response
    
    Headers:
    
    {"cookie"=>[],
     "Cache-Control"=>"no-cache"}

  12. #12
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still can't see anything wrong. I think it must be your InstantRails installation. You could reinstall InstantRails, but I think a proper Rails installation on XP is so simple than you are better doing that than using InstantRails.

    However, before trying that, there is one thing I would suggest doing:

    Change your Controller show method to this:
    Code:
    def show
      @story = Story.find(params[:id])
      @bit_of_text = "bit of text"
    end
    And then change you view code to this:
    Code:
    <h2><&#37;#= @story.name %></h2>
    <p><%#= link_to @story.link, @story.link %></p>
    <p><%= @bit_of_text %></p>
    If that produces an error, post the error message.

    If it doesn't produce an error, have a look at the development.log entry. As you did a Story.find at the controller, the resulting SQL should appear in the log. If you can't work out which part of the log relates to this page request do this:
    • Shut down the web server (stop mongrel)
    • Rename development.log to old_development.log
    • Start the web server.
    • Enter the URL for your show page page (or refresh the page if it is already open) in your browser.

    What you get in the development.log now pure contains what happened since you renamed the log file.

  13. #13
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ReggieB

    I made the changes you suggested.
    The development log showed this:
    Code:
    # Logfile created on Thu Aug 21 13:36:30 -0400 2008
    
    Processing StoriesController#show (for 127.0.0.1 at 2008-08-21 13:37:50) [GET]
      Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D--1bc4cffe024e2fd53d262a4a1427fadf08b93d7d
      Parameters: {"action"=>"show", "id"=>"2", "controller"=>"stories"}
    Rendering template within layouts/application
    Rendering stories/show
    Completed in 0.01600 (62 reqs/sec) | Rendering: 0.01600 (100%) | DB: 0.00000 (0%) | 200 OK [http://localhost/stories/2]
    The browser source code was this:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
    	xml:lang="en" lang="en">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    	<title>Shovell</title>
    	<link href="/stylesheets/style.css?1216495672" media="screen" rel="stylesheet" type="text/css" />
    </head>
    
    <body>
    	<div id="content">
    		<h1>Shovell</h1>
    		
    		<h2></h2>
    <p></p>
    <p></p>
    
    	</div>
    </body>
    </html>
    What should this tell me?

    If I have to reinstall InstantRails, do I have to start back over in the book and work back up to this point?

  14. #14
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webmathetic
    What should this tell me?
    Code:
    <p><&#37;= @bit_of_text %></p>
    Should result as
    Code:
    <p>bit of text</p>
    But instead it is coming out as
    Code:
    <p></p>
    That tells me that the problem is not between your application and the database, but rather between the controller and the view template. That is, data created at the controller is not being passed to the view template.

    There is something fairly fundamentally wrong with your Rails installation. I think the simplest and easiest solution would be to reinstall.
    Quote Originally Posted by webmathetic
    If I have to reinstall InstantRails, do I have to start back over in the book and work back up to this point?
    No ... but ...

    You can copy your whole application to another location to back it up. One of the great things about Rails is that all the application files are simple text files so you can move them very easily.

    So copy your application folder (from an earlier post this looks like shovell at "C:\InstantRails\rails_apps\shovell" on your system) to another location.
    Then uninstall and reinstall InstantRails.
    Then copy the shovell folder back in to the new InstantRails\rails_apps folder.

    And the but! There is a chance the problem is in the application code somewhere. If you follow the instructions and get the same problem, it would probably be simpler to start again.

    However, book's code is available on-line. It may be worth you downloading the code up to your current point and using that.

  15. #15
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,139
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    I've been working trough a few tutorials and have noticed that controller classes are singular (a Ruby "convention"). i.e.
    using
    > ruby script/generate controller Story
    the created file story_controller.rb does NOT look like
    class StoriesController < ApplicationController
    but rather
    class StoryController < ApplicationController

  16. #16
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ReggieB

    Thank you for your help. I will try it as soon as possible.

  17. #17
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is a Rails convention, but I've seen controllers both singular and plural.

    If you enter:
    Code:
    ruby script/generate controller Stories
    you will get:
    stories_controller.rb
    class StoriesController < ApplicationController
    and all your views will be in a folder called 'stories'
    That's just as webmathetic is seeing.

    Also if you:
    Code:
    ruby script/generate scaffold Story
    you will get plural stories controller. That's left me with inconsistencies as I sometimes use Scaffold if I want to add a new model and controller to my application in a hurry.

    As long as you are consistent (file name, controller class, and view folder name all match) it should work. And webmathetic appears to have been consistent.

    If he'd got the controller name wrong he'd get an "uninitialised constant" error. He'd get a "No such file or directory" if the view folder name was wrong.

    So an interesting point well made, but I don't think that is the cause of the problem here.

  18. #18
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,139
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Good point, I'm still a RoR newbie and didn't think of scaffold. Should
    Code:
    <&#37;= link_to @story.link, @story.link %>
    be
    Code:
    <%= link_to 'Method', @story.link %>
    EDIT* Sine I made this post, I've been learning a bit. What was confusing me is that methods are named for what they do, so the above would be
    Code:
    <%= link_to 'Link Text', @story.link %>

  19. #19
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,139
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    I just got the book and have been working through it (I'm up to page 197 - still 10 pages away from your problem).
    The story controller class is indeed class StoriesController < ApplicationController

    Anyway, just a thought, did you put this line in your config\routes.rb file back on page 164?
    Code Ruby:
      # Sample resource route (maps HTTP verbs to controller actions automatically):
    #   map.resources :products
    map.resources :stories

  20. #20
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    I just got the book and have been working through it (I'm up to page 197 - still 10 pages away from your problem).
    The story controller class is indeed class StoriesController < ApplicationController

    Anyway, just a thought, did you put this line in your config\routes.rb file back on page 164?
    Code Ruby:
      # Sample resource route (maps HTTP verbs to controller actions automatically):
    #   map.resources :products
    map.resources :stories
    Yes, I did add that to the code.
    Thanks.

  21. #21
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have reinstalled Rails in a new folder on the C drive. THe problem is that when I do
    Code:
    gem update --system
    the operation times out looking for http://gem.rubyforge.org.

    Also, I have always had the Instant Rails control panel say that the Apache port 80 is used by inetinfo.exe. Does that have anything to do with the first problem?

  22. #22
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,139
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    I can't use InstantRails, but you need to be online when you
    gem update/install.
    This is unfortunate as it seems relatively little time is spent with actual transfer. Most of the time is Gems extracting files etc., but as you don't know when it will make another request, if you go offline the whole process could get aborted.

    *I'm speaking from experience http://www.sitepoint.com/forums/show...89&postcount=3


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
  •