草庐IT

how-to-set-up-the-cassandra-wordc

全部标签

ruby - 是否有与 'new' 哈希语法等效的 Ruby Hash#to_s?

Hash#to_s(inspect的别名)始终以1.8哈希样式输出数据:{key:"value"}.to_s=>"{:key=>\"value\"}"是否有任何核心方法将其序列化为1.9哈希样式?{key:"value"}.to_s=>"{key:\"value\"}"我在已知数据上使用它进行代码重构;由于Ruby倾向于实现所有内容,我希望我只是找错了地方。当然,你可以用丑陋的方式破解它"{"+my_hash.to_a.map{|pair|pair[0].to_s+":"+pair[1].inspect}*",\n")+"}"但我希望有一个经过单元测试且完全正确的核心方法。

ruby-on-rails - Thinking sphinx - 带条件连接的索引 (has_and_belongs_to_many)

我有模型Service,它具有按服务类型ID过滤服务的范围:classServiceids{joins(:service_types).where('service_types_services.service_type_idin(?)',ids)}endclassServiceType所以,当我运行scope时,我得到这样的结果:Service.by_service_types([54])ServiceLoad(0.8ms)SELECT"services".*FROM"services"INNERJOIN"service_types_services"ON"service_types

ruby 雾 gem : how to create sub-directories?

我有connection=Fog::Storage.new(fog_config)bucket=connection.directories.get(bucket_name)有没有办法(已记录、未记录、变通)让我在此存储桶内创建目录?像这样的东西:sub_dir_for_user_1=bucket.create_sub_dir('/user_1_files')sub_dir_for_user_2=bucket.create_sub_dir('/user_2_files') 最佳答案 在S3中,带有尾部斜杠的零字节文件将创建一个伪目录

ruby-on-rails - rspec rails 测试 : how can I force ActiveJob job's to run inline for certain tests?

我希望我的后台作业能够内联运行某些标记测试。我可以通过用perform_enqueueddo包装测试来做到这一点,但我希望能够用元数据标记它们,如果可能的话,它会自动发生。我试过以下方法:it"doeseverythinginthejobtoo",perform_enqueued:truedoendconfig.around(:each)do|example|ifexample.metadata[:perform_enqueued]perform_enqueued_jobsdoexample.runendendend但它会导致错误:undefinedmethod`perform_enq

c - Ruby c 扩展 : How can I catch all exceptions, 包括不是 StandardErrors 的东西?

在ruby中,begin#...rescue#...end不会捕获不是StandardError子类的异常。在C中,rb_rescue(x,Qnil,y,Qnil);VALUEx(void){/*...*/returnQnil;}VALUEy(void){/*...*/returnQnil;}会做同样的事情。我如何从ruby​​C扩展中rescueException=>e(而不仅仅是rescue=>e)? 最佳答案 Ruby需要更多文档。我不得不进入ruby​​源代码,这是我发现的:VALUErb_rescue(VALUE(*b_p

ruby-on-rails - Ruby on Rails 教程 - 5.26 - Sublime Text "Unable to Save"新文件 "spec/support/utilities.rb"

我正在使用SublimeText2,同时遵循MichaelHartl的RubyonRails教程。可以在http://ruby.railstutorial.org/book/ruby-on-rails-tutorial找到我所指的教程的具体部分。(ctrl+F“list5.26”)。我能够创建规范/支持文件。但是,在尝试创建spec/support/utilities.rb文件时,我收到消息“无法保存~/rails_projects/sample_app/spec/support/utilities.rb”。有人知道为什么会这样吗?SublimeText论坛上有人似乎遇到了完全相同的问

ruby - 在 ruby​​ Selenium 中移动鼠标(move_to)

我正在尝试使用Ruby中的SeleniumWebDriver2.4模拟鼠标移动如果我运行测试,是否应该看到鼠标在我的屏幕上移动?我很困惑。我试过很多不同的方法示例代码:require'selenium-webdriver'driver=Selenium::WebDriver.for:firefoxdriver.navigate.to'http://www.google.com'element=driver.find_element(:id,'gbqfba')那我试过了driver.action.move_to(element).performdriver.mouse.move_to(e

ruby-on-rails - 如何在 RubyOnRails 中使用 'acts as nested set' 创建一个可排序的接口(interface)

我一直在为使用acts_as_list的模型实现一些不错的交互界面,这些界面可以对我的mRails应用程序中的列表进行排序。我有一个排序函数,在每次拖放之后使用sortable_elementscript.aculo.us函数调用并设置每条记录的位置。这是在拖放完成后处理排序的Controller操作示例:defsortparams[:documents].each_with_indexdo|id,index|Document.update_all(['position=?',index+1],['id=?',id])endend现在我正在尝试对嵌套集模型(acts_as_nested

ruby 在 `gem_original_require' : no such file to load -- CloudyScripts (LoadError)

在Ubuntu和Ruby1.8.7上,我通过以下方式安装了CloudyScripts:geminstallgeminstallCloudyScripts当我尝试执行此操作时:require'rubygems'require'CloudyScripts'我收到以下错误:/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in`gem_original_require':nosuchfiletoload--CloudyScripts(LoadError)from/usr/lib/ruby/1.8/rubygems/custom_require.r

ruby-on-rails - rails 3/ActiveRecord : How to switch/change table name during request dynamically?

我想在请求期间动态更改ActiveRecord模型类的表名。例如,有许多具有相似结构(列)的表:mydb:sample_data_12222sample_data_12223sample_data_12224sample_data_12225...所以,我想做的是..._1。定义基本模型类,如:classSampleData_2。在请求期间更改目标表,例如:defaction_methodSampleData.set_table_name"sample_data_#{params[:id]}"@rows=SampleData.all如果在非线程环境(如Passenger/mod_rai