Tag: ruby

在Rails中添加可以为空的外键

引用Rails 4.2 add_foreign_key支持: # add a foreign key to `articles.author_id` referencing `authors.id` add_foreign_key :articles, :authors 如何创建一个可以为空的外键约束,以允许这样的情况,其中articles.author_id有时可以为null?

的ActiveRecord :: ConnectionTimeoutError

我收到此错误: ‘could not obtain a database connection within 5 seconds (waited 5.001017 seconds). The max pool size is currently 16; consider increasing it.’ 首先我得到了这个错误,我将计数从5提升到16.但它仍然在发生,我是唯一一个测试数据库的人。 当我是唯一的用户时,为什么会这样? 我不在铁轨上。 我在用: ActiveRecord::Base.establish_connection ({ :adapter => ‘mysql2’, :database => ‘ck’, :host => ‘localhost’, :username => ‘root’, :password => ”, :pool => 16, }) 并使用Sinatra。 谢谢

Ruby DSL(域特定语言)存储库,示例

我正在寻找Ruby DSLs(领域特定语言)的优秀示例。 您知道哪些存储库,项目值得一读? 为什么它(或者是它们)是很好的例子? 我对经过深思熟虑和设计的更复杂的例子特别感兴趣。

在IRB重新加载rubygem

有没有办法在内存中“重新加载”或“刷新”rubygem? 因为我正在玩irb,偶尔我喜欢修改我的gem文件,如果我需要相同的gem,它不会更新到内存中并输出“false”。 目前我必须退出IRB,重新进入IRB然后再次要求gem,必须有更好的方法……它是什么?

从Rails 2迁移到Rails 3

可能重复: Rails 3弃用了方法和API 哪些资源(免费或付费)可以帮助您完成将Ruby on Rails 2应用程序迁移到Rails 3的过程? 我在RoR网站上看到过一些博客文章(其中一些看起来过时了)和一本电子书出售,但你能推荐什么作为从版本2到版本3的变化的准确和完整的解释以及需要什么移植到Rails 3环境时要更新?

RVM ruby​​安装错误 – Mac

我试图通过RVM安装以下三个版本的Ruby,每个版本都有自己的一组错误。 我更关心的是让最后一个工作,所以我会专注于那个。 rvm install 1.8.7 rvm install 1.9.2 rvm install 1.9.3 rvm install 1.9.3(bash输出) 14:10:41: ~/.rvm/config $ rvm install 1.9.3 Fetching yaml-0.1.4.tar.gz to /Users/dionnesaunders/.rvm/archives Extracting yaml-0.1.4.tar.gz to /Users/dionnesaunders/.rvm/src ERROR: Error running ‘tar mzxf /Users/dionnesaunders/.rvm/archives/yaml-0.1.4.tar.gz -C /Users/dionnesaunders/.rvm/src ‘, please read /Users/dionnesaunders/.rvm/log/ruby-1.9.3-p0/yaml/extract.log Configuring yaml in /Users/dionnesaunders/.rvm/src/yaml-0.1.4. ERROR: Error running ‘ ./configure –prefix=”/Users/dionnesaunders/.rvm/usr” ‘, please read /Users/dionnesaunders/.rvm/log/ruby-1.9.3-p0/yaml/configure.log Compiling […]

安装调试器时出错:无法使用ruby-1.9.3-p362构建gem本机扩展

在尝试为新项目运行bundle时,我遇到以下错误: Installing debugger (1.2.2) with native extensions Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. C:/Ruby193/bin/ruby.exe extconf.rb checking for rb_method_entry_t.called_id in method.h… no checking for rb_control_frame_t.method_id in method.h… no checking for rb_method_entry_t.called_id in method.h… no checking for rb_control_frame_t.method_id in method.h… no Makefile creation failed ************************************************************************** No source for ruby-1.9.3-p362 provided with debugger-ruby_core_source gem. ************************************************************************** *** […]

如何使用ActiveRecord按作业数量对作者进行排序?

假设我有Book模型和Author模型。 我想列出按书数排序的所有作者。 最好的方法是什么? 我知道如何在SQL中执行此操作,方法是使用嵌套选择或使用某些连接执行。 但我想知道的是如何使用ActiveRecord很好地完成这项工作。

如何向现有控制器添加新操作?

我在Rails中很新。 抱歉,这个菜鸟问题。 我已经创建了一个新的控制器: rails new controller Say hello goodbye 如何向现有控制器添加“hello”和“goodbye”等新操作?

如何在低内存系统上使用RVM编译ruby?

rvm install 1.9.3 导致make.log中的错误: … compiling ./enc/trans/emoji_sjis_docomo.c compiling ./enc/trans/emoji_sjis_kddi.c gcc: internal compiler error: Killed (program cc1) gcc: internal compiler error: Killed (program cc1) gcc: internal compiler error: Killed (program cc1) Please submit a full bug report, with preprocessed source if appropriate. … dmesg显示 [180031.341709] send sigkill to 3705 (cc1), adj 0, size 3394 在某些时候运行配置过程的free节目: total […]