Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在Ruby on Rails项目中安装gem时出错_Ruby On Rails_Ruby_Postgresql - Fatal编程技术网

Ruby on rails 在Ruby on Rails项目中安装gem时出错

Ruby on rails 在Ruby on Rails项目中安装gem时出错,ruby-on-rails,ruby,postgresql,Ruby On Rails,Ruby,Postgresql,我在ROR-postgresql中创建了一个简单的web项目作为数据库 C:\Sites\nested>ruby -v ruby 1.9.3p484 (2013-11-22) [i386-mingw32] C:\Sites\nested>rails -v Rails 4.0.2 当我尝试通过命令行添加自动外键时 C:\Sites\nested>gem install automatic_foreign_key 或者通过添加 # create automatic forei

我在ROR-postgresql中创建了一个简单的web项目作为数据库

C:\Sites\nested>ruby -v
ruby 1.9.3p484 (2013-11-22) [i386-mingw32]

C:\Sites\nested>rails -v
Rails 4.0.2
当我尝试通过命令行添加自动外键时

C:\Sites\nested>gem install automatic_foreign_key
或者通过添加

# create automatic foreign key
gem "automatic_foreign_key", "~> 1.3.0"
我在运行服务器时遇到以下错误

C:\Sites\nested>rails s                                
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method': undefined method `to_sql' for class `ActiveRecord::ConnectionAdapters::Tab leDefinition' (NameError)
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-.0.2/lib/active_support/core_ext/module/aliasing.rb:32:in `alias_method_chain'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/redhillonrails_core-.2.0/lib/redhillonrails_core/active_record/connection_adapters/table_definition.rb:9:in `block in included'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/redhillonrails_core-.2.0/lib/redhillonrails_core/active_record/connection_adapters/table_definition.rb:6:in `class_eval'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/redhillonrails_core-.2.0/lib/redhillonrails_core/active_record/connection_adapters/table_definition.rb:6:in `included'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/redhillonrails_core-.2.0/lib/redhillonrails_core.rb:32:in `include'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/redhillonrails_core-.2.0/lib/redhillonrails_core.rb:32:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-.0.2/lib/active_support/dependencies.rb:229:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-.0.2/lib/active_support/dependencies.rb:229:in `block in require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-.0.2/lib/active_support/dependencies.rb:229:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/automatic_foreign_key-.3.0/lib/automatic_foreign_key.rb:5:in `rescue in <top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/automatic_foreign_key-.3.0/lib/automatic_foreign_key.rb:1:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:72:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:70:in `each'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:70:in `block in require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:59:in `each'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:59:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler.rb:132:in require'
from C:/Sites/nested/config/application.rb:7:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-.0.2/lib/rails/commands.rb:74:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-.0.2/lib/rails/commands.rb:74:in `block in <top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-.0.2/lib/rails/commands.rb:71:in `tap'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-.0.2/lib/rails/commands.rb:71:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
C:\Sites\nested>rails
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.2/lib/active\u support/core\u ext/module/aliasing.rb:32:in'alias\u method:'ActiveRecord::ConnectionAdapters::Tab leDefinition'类的未定义方法'to\u sql'(名称错误)
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-.0.2/lib/active\u support/core\u ext/module/aliasing.rb:32:in'alias\u method\u chain'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/redhillonrails\u core-.2.0/lib/redhillonrails\u core/active\u record/connection\u adapters/table\u definition.rb:9:“包含的块”中
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/redhillonrails\u core-.2.0/lib/redhillonrails\u core/active\u record/connection\u adapters/table\u definition.rb:6:in'class\u eval'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/redhillonrails\u core-.2.0/lib/redhillonrails\u core/active\u record/connection\u adapters/table\u definition.rb:6:“包含”中
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/redhillonrails\u core-.2.0/lib/redhillonrails\u core.rb:32:in“include”
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/redhillonrails\u core-.2.0/lib/redhillonrails\u core.rb:32:in`'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-.0.2/lib/active\u support/dependencies.rb:229:in'require'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-.0.2/lib/active\u support/dependencies.rb:229:in'block in require'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-.0.2/lib/active\u support/dependencies.rb:214:in'load\u dependencity'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-.0.2/lib/active\u support/dependencies.rb:229:in'require'
从C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/automatic_-foreign_-key-.3.0/lib/automatic_-foreign_-key.rb:5:in'rescue-in'
从C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/automatic\u-foreign\u-key-.3.0/lib/automatic\u-foreign\u-key.rb:1:in`'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:72:in'require'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:72:在“请求中的块(2个级别)”中
从C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:70:in'each'
从C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:70:in'block in require'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:59:in'each'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler/runtime.rb:59:in'require'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/bundler-.3.5/lib/bundler.rb:132:in require'
从C:/Sites/nested/config/application.rb:7:in`'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-.0.2/lib/rails/commands.rb:74:in'require'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-.0.2/lib/rails/commands.rb:74:in'block in'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-.0.2/lib/rails/commands.rb:71:in'tap'
来自C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-.0.2/lib/rails/commands.rb:71:in`'
从箱子/轨道:4:in“require”
从箱子/轨道:4:in`'
试试这个

C:\Sites\nested>gem install --local automatic_foreign_key

另外,在您的项目终端中进行
bundle安装--local
,然后在gem文件中编辑
gem“automatic\u foreign\u key”、“~>1.3.0”
,以供参考。这是您的错误:

`alias_method': undefined method `to_sql' for class `ActiveRecord::ConnectionAdapters::Tab leDefinition' (NameError)
看起来gem正在为
.to\u sql
创建一个。Alias method Basicali以另一个名称调用方法,因此您可以在不同的上下文中使用它

我们经常使用
alias\u方法:name,:title
,因为我们标准化了验证,这意味着每次都需要保持相同的方法名称


错误

实际错误是由于您的类没有
to_sql
方法造成的。我从未遇到过这种情况,因此:

问题似乎是由Rails 4引起的。至于解决方案,我建议,因为它将与Rails 4不兼容


如果我们把这个想法作为问题,也许你可以详细说明你希望它如何工作&我们可以创建一个变通方案?

自动外键
三年前被作者弃用。您可能不应该使用它。安装时发生以下错误--本地错误:执行gem时。。。(Gem::CommandLineError)请在本地系统中安装后指定至少一个Gem名称(例如Gem build GEMNAME),您可以在项目终端中添加
bundle install--local
。该命令未执行!以下错误:执行gem时。。。(Gem::CommandLineError)请指定至少一个Gem名称(例如Gem build GEMNAME)Gem install--local automatic\u foreign\u key==>ERROR:在任何存储中都找不到有效的Gem“automatic\u foreign\u key”(>=0)如果不支持,请在安装时也提及Gem文件版本,降级rails版本是否可以解决问题?当然可以,但这不是小事-如果愿意,您可以尝试,但最好使用最新版本