我一直很难让 Rails 3.2 与 mysql2 一起工作。
我正在运行 OSX 10.6、MySQL 5.1.37
我得到了这个可爱的堆栈跟踪。
HunterMBP:v hunter$ bundle exec rake db:create
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.2/lib/mysql2/mysql2.bundle: [BUG] Segmentation fault
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin10.8.0]
-- Control frame information -----------------------------------------------
c:0033 p:-543968548 s:0099 b:0099 l:000098 d:000098 TOP
c:0032 p:---- s:0097 b:0097 l:000096 d:000096 CFUNC :require
c:0031 p:0107 s:0093 b:0093 l:000092 d:000092 TOP /Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.2/lib/mysql2.rb:8
c:0030 p:---- s:0091 b:0091 l:000090 d:000090 FINISH
c:0029 p:---- s:0089 b:0089 l:000088 d:000088 CFUNC :require
c:0028 p:0026 s:0085 b:0085 l:000065 d:000084 BLOCK /Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/runtime.rb:68
c:0027 p:---- s:0082 b:0082 l:000081 d:000081 FINISH
c:0026 p:---- s:0080 b:0080 l:000079 d:000079 CFUNC :each
c:0025 p:0091 s:0077 b:0077 l:000065 d:000076 BLOCK /Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/runtime.rb:66
c:0024 p:---- s:0071 b:0071 l:000070 d:000070 FINISH
c:0023 p:---- s:0069 b:0069 l:000068 d:000068 CFUNC :each
c:0022 p:0046 s:0066 b:0066 l:000065 d:000065 METHOD /Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/runtime.rb:55
c:0021 p:0021 s:0062 b:0062 l:000061 d:000061 METHOD /Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler.rb:118
c:0020 p:0137 s:0058 b:0058 l:000057 d:000057 TOP /Users/hunter/Workspace/Projects/Visionare/config/application.rb:13
c:0019 p:---- s:0056 b:0056 l:000055 d:000055 FINISH
c:0018 p:---- s:0054 b:0054 l:000053 d:000053 CFUNC :require
c:0017 p:0026 s:0050 b:0050 l:000049 d:000049 TOP /Users/hunter/Workspace/Projects/Visionare/Rakefile:5
c:0016 p:---- s:0048 b:0048 l:000047 d:000047 FINISH
c:0015 p:---- s:0046 b:0046 l:000045 d:000045 CFUNC :load
c:0014 p:0013 s:0042 b:0042 l:000041 d:000041 METHOD /Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25
c:0013 p:0274 s:0038 b:0038 l:000037 d:000037 METHOD /Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:501
c:0012 p:0009 s:0033 b:0033 l:000026 d:000032 BLOCK /Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:82
c:0011 p:0009 s:0031 b:0031 l:000030 d:000030 METHOD /Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:133
c:0010 p:0011 s:0027 b:0027 l:000026 d:000026 METHOD /Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:81
c:0009 p:0019 s:0024 b:0024 l:000017 d:000023 BLOCK /Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:65
c:0008 p:0009 s:0022 b:0022 l:000021 d:000021 METHOD /Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:133
c:0007 p:0011 s:0018 b:0018 l:000017 d:000017 METHOD /Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:63
c:0006 p:0060 s:0015 b:0015 l:000014 d:000014 TOP /Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/bin/rake:33
c:0005 p:---- s:0013 b:0013 l:000012 d:000012 FINISH
c:0004 p:---- s:0011 b:0011 l:000010 d:000010 CFUNC :load
c:0003 p:0127 s:0007 b:0007 l:002398 d:001e70 EVAL /Users/hunter/.rvm/gems/ruby-1.9.3-p125/bin/rake:19
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:002398 d:002398 TOP
-- Ruby level backtrace information ----------------------------------------
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/bin/rake:19:in `<main>'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/bin/rake:19:in `load'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/Users/hunter/Workspace/Projects/Visionare/Rakefile:5:in `<top (required)>'
/Users/hunter/Workspace/Projects/Visionare/Rakefile:5:in `require'
/Users/hunter/Workspace/Projects/Visionare/config/application.rb:13:in `<top (required)>'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler.rb:118:in `require'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/runtime.rb:55:in `require'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/runtime.rb:55:in `each'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/runtime.rb:66:in `block in require'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/runtime.rb:66:in `each'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/bundler-1.1.0/lib/bundler/runtime.rb:68:in `require'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.2/lib/mysql2.rb:8:in `<top (required)>'
/Users/hunter/.rvm/gems/ruby-1.9.3-p125/gems/mysql2-0.3.2/lib/mysql2.rb:8:in `require'
Gemfile 看起来像这样:
source 'https://rubygems.org'
gem 'rails', '3.2.2'
#gem 'json'
gem "mysql2"
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem "rspec-rails", ">= 2.8.1", :group => [:development, :test]
gem "factory_girl_rails", ">= 1.7.0", :group => :test
gem "email_spec", ">= 1.2.1", :group => :test
gem "cucumber-rails", ">= 1.3.0", :group => :test
gem "capybara", ">= 1.1.2", :group => :test
gem "database_cleaner", ">= 0.7.1", :group => :test
gem "launchy", ">= 2.0.5", :group => :test
gem "devise", ">= 2.0.4"
我有 rails 3.2 和 ruby 1.9.3
bundle install 成功生成了这个列表。
Using rake (0.9.2.2)
Using i18n (0.6.0)
Using multi_json (1.1.0)
Using activesupport (3.2.2)
Using builder (3.0.0)
Using activemodel (3.2.2)
Using erubis (2.7.0)
Using journey (1.0.3)
Using rack (1.4.1)
Using rack-cache (1.2)
Using rack-test (0.6.1)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.1.2)
Using actionpack (3.2.2)
Using mime-types (1.17.2)
Using polyglot (0.3.3)
Using treetop (1.4.10)
Using mail (2.4.3)
Using actionmailer (3.2.2)
Using arel (3.0.2)
Using tzinfo (0.3.32)
Using activerecord (3.2.2)
Using activeresource (3.2.2)
Using addressable (2.2.7)
Using bcrypt-ruby (3.0.1)
Using nokogiri (1.5.2)
Using ffi (1.0.11)
Using childprocess (0.3.1)
Using rubyzip (0.9.6.1)
Using selenium-webdriver (2.20.0)
Using xpath (0.1.4)
Using capybara (1.1.2)
Using coffee-script-source (1.2.0)
Using execjs (1.3.0)
Using coffee-script (2.2.0)
Using rack-ssl (1.3.2)
Using json (1.6.5)
Using rdoc (3.12)
Using thor (0.14.6)
Using railties (3.2.2)
Using coffee-rails (3.2.2)
Using diff-lcs (1.1.3)
Using gherkin (2.9.0)
Using term-ansicolor (1.0.7)
Using cucumber (1.1.9)
Using cucumber-rails (1.3.0)
Using database_cleaner (0.7.1)
Using orm_adapter (0.0.6)
Using warden (1.1.1)
Using devise (2.0.4)
Using rspec-core (2.8.0)
Using rspec-expectations (2.8.0)
Using rspec-mocks (2.8.0)
Using rspec (2.8.0)
Using email_spec (1.2.1)
Using factory_girl (2.6.3)
Using factory_girl_rails (1.7.0)
Using jquery-rails (2.0.1)
Using launchy (2.0.5)
Using mysql2 (0.3.2)
Using bundler (1.1.0)
Using rails (3.2.2)
Using rspec-rails (2.8.1)
Using sass (3.1.15)
Using sass-rails (3.2.4)
Using uglifier (1.2.3)
最佳答案
rvm reset
然后运行
bundle install
帮我解决了这个问题:)
关于mysql - MySQL2/Ruby 1.9.3/Rails 3.2 上的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9667091/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
我有一个字符串input="maybe(thisis|thatwas)some((nice|ugly)(day|night)|(strange(weather|time)))"Ruby中解析该字符串的最佳方法是什么?我的意思是脚本应该能够像这样构建句子:maybethisissomeuglynightmaybethatwassomenicenightmaybethiswassomestrangetime等等,你明白了......我应该一个字符一个字符地读取字符串并构建一个带有堆栈的状态机来存储括号值以供以后计算,还是有更好的方法?也许为此目的准备了一个开箱即用的库?
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
这似乎应该有一个直截了当的答案,但在Google上花了很多时间,所以我找不到它。这可能是缺少正确关键字的情况。在我的RoR应用程序中,我有几个模型共享一种特定类型的字符串属性,该属性具有特殊验证和其他功能。我能想到的最接近的类似示例是表示URL的字符串。这会导致模型中出现大量重复(甚至单元测试中会出现更多重复),但我不确定如何让它更DRY。我能想到几个可能的方向...按照“validates_url_format_of”插件,但这只会让验证干给这个特殊的字符串它自己的模型,但这看起来很像重溶液为这个特殊的字符串创建一个ruby类,但是我如何得到ActiveRecord关联这个类模型
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits