如何解决 ROR-4 中的 NoMethod 错误 [英] How to solve NoMethod error in ROR-4

查看:92
本文介绍了如何解决 ROR-4 中的 NoMethod 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我解决以下错误.当我在 ruby​​ cmd 中输入 rake db:create 时,我得到了这种类型的错误.

Please help me to solve the following error. When I typed rake db:create in ruby cmd i got such type of error.

错误:

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文件如下.

My database.yml and gem file is given below.

config/database.yml

config/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'] %>

宝石文件

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​​ 版本 1.9.3 和 Rails 版本 4.0.2.

As I am new to ROR please help to solve this error and run the command successfully.I am using ruby version-1.9.3 and Rails version 4.0.2.

推荐答案

对我来说,这是 database.yml 中错误的未注释注释行.对您来说,database.yml 的格式似乎不正确.尝试更改以下部分的格式.

For me, it was a mistakenly uncommented comment line in the database.yml. For you, the format of your database.yml seems not right. Try and change the format of the following sections.

替换

    development:<<:*default
      database:mysqlapp_development

   development:
     <<:*default
     database:mysqlapp_development

这篇关于如何解决 ROR-4 中的 NoMethod 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆