【问题标题】:Ruby scaffold undefined method 'configure'Ruby 脚手架未定义方法“配置”
【发布时间】:2025-12-01 07:45:01
【问题描述】:

您好,我完全按照在 Windows 上为 Rubys 创建演示应用程序的步骤进行操作。但是当我尝试使用脚手架命令生成表时,

rails generate scaffold User name:string email:string

我收到以下错误:

C:/Users/YoYo/Ruby_Projects/demo_app/config/environments/development.rb:1:in `<t
op (required)>': undefined method `configure' for #<DemoApp::Application:0x00000
00534bc00> (NoMethodError)
    from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-4.0.5/lib/act
ive_support/dependencies.rb:229:in `require'
    from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-4.0.5/lib/act
ive_support/dependencies.rb:229:in `block in require'
    from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-4.0.5/lib/act
ive_support/dependencies.rb:214:in `load_dependency'
    from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-4.0.5/lib/act
ive_support/dependencies.rb:229:in `require'
    from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.5/lib/rails/en
gine.rb:591:in `block (2 levels) in <class:Engine>'
    from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.5/lib/rails/en
gine.rb:590:in `each'
     from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.5/lib/rails/en
gine.rb:590:in `block in <class:Engine>'
    from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.5/lib/rails/in
itializable.rb:30:in `instance_exec'
    from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.5/lib/rails/in
itializable.rb:30:in `run'
    from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.5/lib/rails/in
itializable.rb:55:in `block in run_initializers'
    from D:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'

    from D:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in
each_strongly_connected_component'
    from D:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:210:in `block (2 levels) in
each_strongly_connected_component_from'
    from D:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connec
ted_component_from'
    from D:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:209:in `block in each_strong
ly_connected_component_from'
    from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.5/lib/rails/in
itializable.rb:44:in `each'
    from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.5/lib/rails/in
itializable.rb:44:in `tsort_each_child'
    from D:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:203:in `each_strongly_connec
ted_component_from'
    from D:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strong
ly_connected_component'
    from D:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:180:in `each'
    from D:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connec
ted_component'
    from D:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
    from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.5/lib/rails/in
itializable.rb:54:in `run_initializers'
    from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.5/lib/rails/ap
plication.rb:215:in `initialize!'
    from C:/Users/YoYo/Ruby_Projects/demo_app/config/environment.rb:5:in `<t
op (required)>'
    from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.5/lib/rails/ap
plication.rb:189:in `require'
    from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.5/lib/rails/ap
plication.rb:189:in `require_environment!'
    from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.5/lib/rails/co
mmands.rb:44:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

有人知道怎么解决吗?

【问题讨论】:

  • demo_app/config/environments/development.rb 文件的第一行应为DemoApp::Application.configure。请发布您的development.rb 文件。

标签: ruby-on-rails scaffold


【解决方案1】:

所以你的配置有问题---

你可以使用-

DemoApp::Application.configure do
    config.cache_classes = false
    config.consider_all_requests_local       = true
    config.action_controller.perform_caching = false
    config.action_mailer.raise_delivery_errors = false
    config.active_support.deprecation = :log
    config.active_record.migration_error = :page_load
    config.assets.debug = true
    config.assets.raise_runtime_errors = true
   end

rails-generate-scaffold-error

【讨论】:

  • 对于想知道为什么会出现这个问题的人,您可能使用高于或等于 4.1.x 的 Rails 版本运行 rails new ...,然后通过宝石文件。 Rails 4.1.x+ 使用 Rails.application.configure 而旧版本的 Rails 4 使用 AppName::Application.configure。可以在安装过程中指定您想要的导轨版本,如下所示:rails _4.x.x_ new appname