NoMethodError

Start with a new project

ruby -rubygems /home/rubys/git/rails/bin/rails testapp
      create  
      create  README
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/views/layouts/application.html.erb
      create  app/controllers/application_controller.rb
      create  app/helpers/application_helper.rb
      create  app/models
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/environments
      create  config/environments/test.rb
      create  config/environments/production.rb
      create  config/environments/development.rb
      create  config/initializers
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/inflections.rb
      create  config/initializers/session_store.rb
      create  config/initializers/mime_types.rb
      create  config/initializers/secret_token.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  doc
      create  doc/README_FOR_APP
      create  lib
      create  lib/tasks
      create  lib/tasks/.gitkeep
      create  log
      create  log/server.log
      create  log/production.log
      create  log/development.log
      create  log/test.log
      create  public
      create  public/404.html
      create  public/index.html
      create  public/favicon.ico
      create  public/422.html
      create  public/500.html
      create  public/robots.txt
      create  public/images
      create  public/images/rails.png
      create  public/stylesheets
      create  public/stylesheets/.gitkeep
      create  public/javascripts
      create  public/javascripts/prototype.js
      create  public/javascripts/controls.js
      create  public/javascripts/rails.js
      create  public/javascripts/application.js
      create  public/javascripts/effects.js
      create  public/javascripts/dragdrop.js
      create  script
      create  script/rails
      create  test
      create  test/performance/browsing_test.rb
      create  test/test_helper.rb
      create  test/fixtures
      create  test/unit
      create  test/functional
      create  test/integration
      create  tmp
      create  tmp/sessions
      create  tmp/sockets
      create  tmp/cache
      create  tmp/pids
      create  vendor/plugins
      create  vendor/plugins/.gitkeep
bundle install
Using rake (0.8.7) from bundler gems 
Using abstract (1.0.0) from bundler gems 
Using builder (2.1.2) from bundler gems 
Using i18n (0.4.0.beta1) from bundler gems 
Using memcache-client (1.8.3) from bundler gems 
Using tzinfo (0.3.20) from bundler gems 
Using activesupport (3.0.0.beta3) from source code at /home/rubys/git/rails 
Using activemodel (3.0.0.beta3) from source code at /home/rubys/git/rails 
Using erubis (2.6.5) from bundler gems 
Using rack (1.1.0) from bundler gems 
Using rack-mount (0.6.3) from bundler gems 
Using rack-test (0.5.3) from bundler gems 
Using actionpack (3.0.0.beta3) from source code at /home/rubys/git/rails 
Using mime-types (1.16) from bundler gems 
Using polyglot (0.3.1) from bundler gems 
Using treetop (1.4.5) from bundler gems 
Using mail (2.2.0) from bundler gems 
Using text-hyphen (1.0.0) from bundler gems 
Using text-format (1.0.0) from bundler gems 
Using actionmailer (3.0.0.beta3) from source code at /home/rubys/git/rails 
Using arel (0.3.3) from bundler gems 
Using activerecord (3.0.0.beta3) from source code at /home/rubys/git/rails 
Using activeresource (3.0.0.beta3) from source code at /home/rubys/git/rails 
Using bundler (0.9.25) from bundler gems 
Using thor (0.13.6) from bundler gems 
Using railties (3.0.0.beta3) from source code at /home/rubys/git/rails 
Using rails (3.0.0.beta3) from source code at /home/rubys/git/rails 
Using sqlite3-ruby (1.2.5) from bundler gems Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

About as simple of a scaffold as you can get

rails generate scaffold product title:string
      invoke  active_record
      create    db/migrate/20100505102717_create_products.rb
      create    app/models/product.rb
      invoke    test_unit
      create      test/unit/product_test.rb
      create      test/fixtures/products.yml
       route  resources :products
      invoke  scaffold_controller
      create    app/controllers/products_controller.rb
      invoke    erb
      create      app/views/products
      create      app/views/products/index.html.erb
      create      app/views/products/edit.html.erb
      create      app/views/products/show.html.erb
      create      app/views/products/new.html.erb
      create      app/views/products/_form.html.erb
      invoke    test_unit
      create      test/functional/products_controller_test.rb
      invoke    helper
      create      app/helpers/products_helper.rb
      invoke      test_unit
      create        test/unit/helpers/products_helper_test.rb
      invoke  stylesheets
      create    public/stylesheets/scaffold.css
rake db:migrate
mv 20100505102717_create_products.rb 20100301000001_create_products.rb
(in /home/rubys/tmp/work/testapp)
==  CreateProducts: migrating =================================================
-- create_table(:products)
   -> 0.0011s
==  CreateProducts: migrated (0.0012s) ========================================
 

Start the server.

Insert an error into the index

edit app/views/products/index.html.erb
<h1>Listing products</h1>
 
<table>
  <tr>
    <th>Title</th>
    <th></th>
    <th></th>
    <th></th>
  </tr>
 
<% @products.each do |product| %>
  <tr>
    <td><%= product.title %></td>
    <td><%= link_to 'Show', product %></td>
    <td><%= link_to 'Edit', edit_product_path(product) %></td>
    <td><%= link_to 'Destroy', product, :confirm => 'Are you sure?', :method => :delete %></td>
  </tr>
<% end %>
</table>
 
<br />
 
<%= link_to 'New Product', new_product_path %>
<%= @foo.bar %>

Verify the stack traceback

get /products

NoMethodError in Products#index

Showing /home/rubys/tmp/work/testapp/app/views/products/index.html.erb where line #24 raised:

undefined method `bar' for nil:NilClass

Extracted source (around line #24):

21: <br />
22: 
23: <%= link_to 'New Product', new_product_path %>
24: <%= @foo.bar %>

Rails.root: /home/rubys/tmp/work/testapp

Application Trace | Framework Trace | Full Trace
app/views/products/index.html.erb:24
app/controllers/products_controller.rb:7:in `index'

Request

Parameters:

None

Show session dump

Show env dump

Response

Headers:

None

Create a product

get /products/new

New product


Back
post /products
  • product[title] => Web Design for Dummies
You are being redirected.
get http://localhost:3000/products/1

Product was successfully created.

Title: Web Design for Dummies

Edit | Back

Verify the stack traceback

get /products

500 Internal Server Error

If you are the administrator of this website, then please read this web application's log file and/or the web server's log file to find out what went wrong.
Expected at least 1 element matching "code", found 0.

Traceback:
  no_method_error.rb:30
  /home/rubys/git/gorp/lib/gorp/test.rb:148:in `call'
  /home/rubys/git/gorp/lib/gorp/test.rb:148:in `get'
  no_method_error.rb:29

Environment

Wed, 05 May 2010 10:27:27 GMT
/home/rubys/.rvm/rubies/ruby-1.8.7-p249/bin/ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]
gem -v
1.3.6
bundle show
Gems included by the bundle:
  * abstract (1.0.0)
  * actionmailer (3.0.0.beta3)
  * actionpack (3.0.0.beta3)
  * activemodel (3.0.0.beta3)
  * activerecord (3.0.0.beta3)
  * activeresource (3.0.0.beta3)
  * activesupport (3.0.0.beta3)
  * arel (0.3.3)
  * builder (2.1.2)
  * bundler (0.9.25)
  * erubis (2.6.5)
  * i18n (0.4.0.beta1)
  * mail (2.2.0)
  * memcache-client (1.8.3)
  * mime-types (1.16)
  * polyglot (0.3.1)
  * rack (1.1.0)
  * rack-mount (0.6.3)
  * rack-test (0.5.3)
  * rails (3.0.0.beta3 743d77)
  * railties (3.0.0.beta3)
  * rake (0.8.7)
  * sqlite3-ruby (1.2.5)
  * text-format (1.0.0)
  * text-hyphen (1.0.0)
  * thor (0.13.6)
  * treetop (1.4.5)
  * tzinfo (0.3.20)
rake about
(in /home/rubys/tmp/work/testapp)
About your application's environment
Ruby version              1.8.7 (x86_64-linux)
RubyGems version          1.3.6
Rack version              1.1
Rails version             3.0.0.beta3
Active Record version     3.0.0.beta3
Action Pack version       3.0.0.beta3
Active Resource version   3.0.0.beta3
Action Mailer version     3.0.0.beta3
Active Support version    3.0.0.beta3
Middleware                ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::RemoteIp, Rack::Sendfile, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::MethodOverride, ActionDispatch::Head
Application root          /home/rubys/tmp/work/testapp
Environment               development
git log -1
commit 743d77f405a16cd1cf1d4bbccd6b512463e10a43
Author: wycats <wycats@gmail.com>
Date:   Wed May 5 06:19:42 2010 +0200

    Update hidden namespace mechanism to work better with alternate choices and to support full namespaces (not just entire groups)