gpt4 book ai didi

ruby-on-rails - 运行生成脚手架命令时出现未定义方法 `groups'错误

转载 作者:太空宇宙 更新时间:2023-11-03 16:55:56 25 4
gpt4 key购买 nike

我对 Ruby 和 Rails 完全陌生,运行此命令时出现错误:

rails generate scaffold User name:string email:string

这是我得到的完整错误:

/Users/ad7863/rails_project/demo_app/config/application.rb:7: undefined method `groups' for Rails:Module (NoMethodError)
from /Library/Ruby/Gems/1.8/gems/railties-3.0.11/lib/rails/commands.rb:15:in `require'
from /Library/Ruby/Gems/1.8/gems/railties-3.0.11/lib/rails/commands.rb:15
from script/rails:6:in `require'
from script/rails:6

我正在学习可以找到的 Ruby on Rails 教程 here .

我使用的是 Rails 版本 3.0.11。

有人知道我做错了什么吗?

谢谢。

编辑:我的 application.rb 文件的内容:

require File.expand_path('../boot', __FILE__)

require 'rails/all'

if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end

module DemoApp
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.

# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)

# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]

# Activate observers that should always be running.
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer

# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de

# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"

# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]

# Enable the asset pipeline
config.assets.enabled = true

# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'


end
end

最佳答案

在 application.rb 文件的第 7 行,更改:

Bundler.require(*Rails.groups(:assets => %w(development test)))

到:

# Bundler.require(*Rails.groups(:assets => %w(development test)))

关于ruby-on-rails - 运行生成脚手架命令时出现未定义方法 `groups'错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9710428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com