SitePoint Sponsor

User Tag List

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

    Scaffold problem

    I have experiencing some problems with the usage of scaffold.
    I have defined a controller as followings:

    class ListItemsController < ApplicationController
    scaffold :list_item
    end

    After that I try to access the webpage but it gives the following errors:
    Does anybody experience the same error before? Any idea to get across it?

    NoMethodError in List itemsController#index

    undefined method `scaffold' for ListItemsController:Class

    RAILS_ROOT: /home/user/projects/ShoppingList
    Application Trace | Framework Trace | Full Trace

    app/controllers/list_items_controller.rb:2

    vendor/rails/activesupport/lib/active_support/dependencies.rb:203:in `load_without_new_constant_marking'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:203:in `load_file'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:202:in `load_file'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:94:in `require_or_load'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:248:in `load_missing_constant'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:453:in `const_missing'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:465:in `const_missing'
    vendor/rails/activesupport/lib/active_support/inflector.rb:257:in `constantize'
    vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb:148:in `constantize'
    vendor/rails/actionpack/lib/action_controller/routing.rb:1426:in `recognize'
    vendor/rails/actionpack/lib/action_controller/dispatcher.rb:170:in `handle_request'
    vendor/rails/actionpack/lib/action_controller/dispatcher.rb:115:in `dispatch'
    vendor/rails/actionpack/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'
    vendor/rails/actionpack/lib/action_controller/dispatcher.rb:9:in `dispatch'
    vendor/rails/railties/lib/webrick_server.rb:112:in `handle_dispatch'
    vendor/rails/railties/lib/webrick_server.rb:78:in `service'
    /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    /usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
    vendor/rails/railties/lib/webrick_server.rb:62:in `dispatch'
    vendor/rails/railties/lib/commands/servers/webrick.rb:66
    /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
    /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in `require'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in `require'
    vendor/rails/railties/lib/commands/server.rb:39
    script/server:3:in `require'
    script/server:3

    app/controllers/list_items_controller.rb:2
    vendor/rails/activesupport/lib/active_support/dependencies.rb:203:in `load_without_new_constant_marking'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:203:in `load_file'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:202:in `load_file'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:94:in `require_or_load'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:248:in `load_missing_constant'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:453:in `const_missing'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:465:in `const_missing'
    vendor/rails/activesupport/lib/active_support/inflector.rb:257:in `constantize'
    vendor/rails/activesupport/lib/active_support/core_ext/string/inflections.rb:148:in `constantize'
    vendor/rails/actionpack/lib/action_controller/routing.rb:1426:in `recognize'
    vendor/rails/actionpack/lib/action_controller/dispatcher.rb:170:in `handle_request'
    vendor/rails/actionpack/lib/action_controller/dispatcher.rb:115:in `dispatch'
    vendor/rails/actionpack/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'
    vendor/rails/actionpack/lib/action_controller/dispatcher.rb:9:in `dispatch'
    vendor/rails/railties/lib/webrick_server.rb:112:in `handle_dispatch'
    vendor/rails/railties/lib/webrick_server.rb:78:in `service'
    /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    /usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
    vendor/rails/railties/lib/webrick_server.rb:62:in `dispatch'
    vendor/rails/railties/lib/commands/servers/webrick.rb:66
    /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
    /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in `require'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in'
    vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in `require'
    vendor/rails/railties/lib/commands/server.rb:39
    script/server:3:in `require'
    script/server:3

    Request

    Parameters:

    None

    Show session dump

    ---
    flash: !map:ActionController::Flash::FlashHash {}

  2. #2
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,115
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    Rails 2.0 removed these temporary scaffolds.

    You need to run the generator like the following from the command line to actually create the files:
    Code:
    ruby script/generate scaffold

  3. #3
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To be more precise, remove the controller you've already created with:
    Code:
    script/destroy controller ListItems
    And then use the scaffold generator:
    Code:
    script/generate scaffold ListItem name:string cost:float quantity:integer

  4. #4
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically, you're following old instructions. Dynamic scaffolding (the "scaffold :list_item" bit there) hasn't been valid for quite some time now (it went out with Rails 2.0).

    Downside, you have to wipe the old model and recreate it with the scaffold generator. And when you do so, add "--skip-migration" to the scaffold generator line. That way you avoid generating a new migration (assuming, of course, you're rebuilding the model with the same fields).

    Unless, that is you want to start from scratch with the model, then after you destroy it you need to walk back the migration that created the fields.


Tags for this Thread

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
  •