如何解决ROR-4中的NoMethod错误

时间:2015-01-13 11:08:51

标签: ruby ruby-on-rails-4

请帮我解决以下错误。当我输入rake db:在ruby cmd中创建时,我遇到了这种类型的错误。

错误:

rake aborted!
NoMethodError: undefined method `each' for #<String:0x1a1af20>

Tasks: TOP => db:create => db:load_config
(See full trace by running task with --trace)

我的database.yml和gem文件如下所示。

配置/ database.yml的

# MySQL.  Versions 5.0+ are recommended.
#
# Install the MYSQL driver
#   gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
#   gem 'mysql2'
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
#
default:&default
  adapter:mysql2
  encoding:utf8
  pool:5
  username:root
  password:pass
  host:localhost

development:<<:*default
  database:mysqlapp_development

# 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:<<:*default
  database:mysqlapp_test

# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
#   DATABASE_URL="mysql2://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
#   production:
#     url: <%= ENV['DATABASE_URL'] %>
#
production:<<:*default
  database:mysqlapp_production
  username:mysqlapp
  password:<%= ENV['MYSQLAPP_DATABASE_PASSWORD'] %>

的Gemfile

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use mysql as the database for Active Record
gem 'mysql2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'debugger' anywhere in the code to stop execution and get a debugger console
  gem 'debugger'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

由于我是ROR的新手,请帮助解决此错误并成功运行命令。我使用的是ruby version-1.9.3和Rails版本4.0.2。

1 个答案:

答案 0 :(得分:0)

对我来说,这是在database.yml中错误地取消注释的注释行。对你来说,你的database.yml的格式似乎不对。尝试并更改以下部分的格式。

替换

    development:<<:*default
      database:mysqlapp_development

   development:
     <<:*default
     database:mysqlapp_development