【问题标题】:Ruby: can't convert true into StringRuby:无法将 true 转换为字符串
【发布时间】:2014-04-08 02:06:11
【问题描述】:

这里是 Ruby on Rails 开发新手。我最近从一个正在构建 iPhone 应用程序的远程团队提取代码,包括用于 Rails 后端的 API,但是一旦我完成提取代码,当我尝试启动 Rails 服务器时,我在终端中收到以下错误。

/usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/runtime.rb:68:in `require': can't convert true into String (TypeError)
   from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
   from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/runtime.rb:66:in `each'
   from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/runtime.rb:66:in `block in require'
   from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/runtime.rb:55:in `each'
   from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/runtime.rb:55:in `require'
   from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler.rb:119:in `require'
   from /Users/tmylonas/Sites/getlocal/config/application.rb:7:in `<top (required)>'
   from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:53:in `require'
   from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:53:in `block in <top (required)>'
   from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:50:in `tap'
   from /usr/local/rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:50:in `<top (required)>'
   from script/rails:6:in `require'
   from script/rails:6:in `<main>'

这是 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 Getlocal
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}/lib)

# 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 escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true

# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql

# Enforce whitelist mode for mass assignment.
# This will create an empty whitelist of attributes available for mass-assignment for all models
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
# parameters by using an attr_accessible or attr_protected declaration.
config.active_record.whitelist_attributes = true

# 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'
config.assets.initialize_on_precompile = false
end
end

这是 gem 文件:

source 'https://rubygems.org'
ruby '1.9.3'
gem 'rails', '3.2.8'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'pg'
gem 'devise'
gem 'simple_form'
gem 'thin'
gem 'cancan'
gem 'sidekiq'
gem 'sinatra', require: false
gem 'slim'
gem 'kaminari'
gem 'high_voltage'
gem 'bootbox-rails'
gem 'rails_autolink'
gem 'newrelic_rpm'
gem "active_model_serializers", "~> 0.8.1"
gem 'google_places'
gem 'figaro'
gem 'houston', :require => true


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'underscore-rails'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

group :development, :test do 
  gem 'pry'
  gem 'pry-rails'
end

group :development do 
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'sextant'
end

不幸的是,这个错误非常难以描述。我不确定这个问题对于 SO 是否足够具体。如果不是,道歉,但在谷歌搜索几个小时后,阅读这样的线程:can't convert true into String 和这个:Ruby returns TypeError: can't convert Object into String,代码是可识别的,我想我会看看是否可以让某人给我关于如何诊断并最终解决此问题的一些更具体的建议。

非常感谢。

【问题讨论】:

  • 你能显示 Gemfile 吗?
  • 你好 Santosh,意识到这被否决了,这显然不适合 SO,但我还是继续添加了 gemfile。感谢您的关注!

标签: ruby-on-rails ruby


【解决方案1】:

像往常一样,回答我的 SO 问题的最佳方式是完成提交问题的过程,等待 24 小时,然后再试一次。

这里的问题是我不熟悉的“Houston” gem 似乎不适用于 Ruby 1.9.3。一旦我从 gemfile 中注释掉那个 gem(感谢 Santosh 建议我发布 gemfile,因为这就是我深入研究它的原因!),Rails 服务器立即启动。

【讨论】:

    猜你喜欢
    • 2011-11-09
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-23
    相关资源
    最近更新 更多