【问题标题】:undefined method `each' for #<String:0x00000003a27a58>#<String:0x00000003a27a58> 的未定义方法“每个”
【发布时间】:2016-11-10 05:57:26
【问题描述】:

首先,我真的很抱歉,因为我还是新手。

我试图按照以下网站上的说明安装 Fat Free CRM:

http://www.blogdugeek.fr/crm-installation-fat-free-crm-debian-squeeze/

http://guides.fatfreecrm.com/Setup-Linux-or-Mac-OS.html

按照说明进行操作时,我遇到了一些错误并解决了一些问题。但是,在执行此命令时:

RAILS_ENV=production rake db:create db:migrate crm:settings:load

我被困在这个命令行中,下面是我一直遇到的以下错误:

rake aborted!
NoMethodError: undefined method `each' for #<String:0x00000003a27a58>
  /usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:150:in `resolve_all'
  /usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.6/lib/active_record/connection_handling.rb:69:in `resolve'
  /usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.6/lib/active_record/core.rb:46:in `configurations='
  /usr/local/rvm/gems/ruby-2.2.4/gems/activerecord-4.2.6/lib/active_record/railties/databases.rake:5:in `block (2 levels) in <top (required)>'
  /usr/local/rvm/gems/ruby-2.2.4/bin/ruby_executable_hooks:15:in `eval'
  /usr/local/rvm/gems/ruby-2.2.4/bin/ruby_executable_hooks:15:in `<main>'

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

在搜索更多相关问题时,我找到了一些,但仍然没有用。

另外,这里有一些可能需要的数据:

Ruby 版本

ruby 2.2.4p230(2015-12-16 修订版 53155)[x86_64-linux]

Rails 版本

Rails 4.2.6

这是错误行

connection_specification.rb

 def resolve(config)
      if config
        resolve_connection config
      elsif env = ActiveRecord::ConnectionHandling::RAILS_ENV.call
        resolve_symbol_connection env.to_sym
      else
        raise AdapterNotSpecified
      end
    end

    # Expands each key in @configurations hash into fully resolved hash
    def resolve_all
      config = configurations.dup
      config.each do |key, value|               <---- Error line
        config[key] = resolve(value) if value
      end
      config
    end

connection_handling.rb

    class MergeAndResolveDefaultUrlConfig # :nodoc:
  def initialize(raw_configurations)
    @raw_config = raw_configurations.dup
    @env = DEFAULT_ENV.call.to_s
  end

  # Returns fully resolved connection hashes.
  # Merges connection information from `ENV['DATABASE_URL']` if available.
  def resolve
    Error line ---->    ConnectionAdapters::ConnectionSpecification::Resolver.new(config).resolve_all 
  end

  private
    def config
      @raw_config.dup.tap do |cfg|
        if url = ENV['DATABASE_URL']
          cfg[@env] ||= {}
          cfg[@env]["url"] ||= url
        end
      end
    end

core.rb

def self.configurations=(config)
    Error line --->     @@configurations = ActiveRecord::ConnectionHandling::MergeAndResolveDefaultUrlConfig.new(config).resolve
  end
  self.configurations = {}

  # Returns fully resolved configurations hash
  def self.configurations
    @@configurations
  end

databases.rake

db_namespace = namespace :db do task :load_config do
Error line ---->   ActiveRecord::Base.configurations       = ActiveRecord::Tasks::DatabaseTasks.database_configuration || {}
ActiveRecord::Migrator.migrations_paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths

这是 config/database.yml 文件。

# MySQL.  Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
#   gem install mysql2
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
#------------------------------------------------------------------------------
development:&development
  adapter:mysql2
  encoding:utf8
  database:fat_free_crm_development
  pool:5
  username:root
#  password:
  socket:/var/run/mysqld/mysqld.sock

# 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:
  <<: *development
  database: fat_free_crm_test

production:
  adapter: mysql
  encoding: utf8
  database: fat_free_crm_production
  pool: 5
  username: root
  password: 
  socket: /var/run/mysqld/mysqld.sock 
 socket: /tmp/mysql.sock

staging:
  <<: *development
  database: fat_free_crm_staging

希望听到并寻求一些建议和学习。 如果需要更多信息,请告诉我。

谢谢,

【问题讨论】:

  • 可能是config/database.yml 中的错误。请发布该文件。
  • 您在调试错误方面做得很好,但您忘记检查错误行附近的数据。如果您在错误行之前将require "pp"; pp config 添加到connection_specification.rb 中,您可能已经自己解决了错误。记住这个技巧以备不时之需。
  • 请不要发布其他文件作为答案。只需编辑原始问题并将其添加到末尾即可。
  • 抱歉,编辑完成。 :)
  • Casper 先生再次抱歉给您带来麻烦。关于这个我应该把require "pp"; pp confing放在哪里?在config = configurations.dup config.each do |key, value| 之前还是在.dup 和.each 之间?对不起,我是新手。 :(

标签: ruby-on-rails ruby installation


【解决方案1】:

您的database.yml 是问题所在。 YAML 需要在键和数据之间使用分隔符。

所以不是这样的:

production:
  adapter:mysql
  encoding:utf8
  ...

但是像这样:

 production:
   adapter: mysql
   encoding: utf8
   ...

你需要更正文件中的所有行,因为你到处都有这个错误。

【讨论】:

  • 对不起,麻烦先生,因为我已经编辑了 database.yml,所以在执行此命令行时发生错误 RAILS_ENV=production rake db:create db:migrate crm:settings:加载
  • 发布编辑后的database.yml 文件(从您的问题中删除旧文件,然后将新版本粘贴到问题中)。您可能仍然在某个地方有错误。
  • @Peter 您的文件中仍有错误。您必须编辑所有行。 developmenttest...所有这些。如果您甚至有一行缺少空格,则文件将无法正确加载。
  • 先生,我已经完成了对yamllint.com 的编辑和验证。但是,在运行 Rails 命令后,我仍然遇到同样的问题。另外,我已经在问题上编辑了 database.yml。
【解决方案2】:

再次检查database.yml 文件。不要添加任何东西 即文件格式必须正确。 不知不觉地评论了导致错误的一行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-11
    • 1970-01-01
    • 2013-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-07
    相关资源
    最近更新 更多