Tag: ruby

来自Ruby的系统调用

如何在Ruby中调用终端调用? 我可以在我的Rails程序中运行“rake db:migrate VERSION = ….”吗?

如何直接在Ruby中激活原始MongoDB查询

有没有办法可以直接在Ruby中激活原始mongo查询而不是将它们转换为本机Ruby对象? 我浏览了Ruby Mongo教程,但我无法在任何地方找到这样的方法。 如果它是mysql,我会发出这样的查询。 ActiveRecord::Base.connection.execute(“Select * from foo”) 我的mongo查询有点大,它在MongoDB控制台中正确执行。 我想要的是直接在Ruby代码中执行相同的内容。

Rails控制台未加载

尝试启动rails console我不断收到以下错误 Users/rigelstpierre/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/completion.rb:9:in `require’: dlopen(/Users/rigelstpierre/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.4.0/readline.bundle, 9): Library not loaded: /Users/rigelstpierre/.rvm/usr/lib/libreadline.6.2.dylib (LoadError) Referenced from: /Users/rigelstpierre/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.4.0/readline.bundle Reason: image not found – /Users/rigelstpierre/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/x86_64-darwin11.4.0/readline.bundle from /Users/rigelstpierre/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/irb/completion.rb:9:in `’ from /Users/rigelstpierre/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.2/lib/rails/commands/console.rb:3:in `require’ from /Users/rigelstpierre/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.2/lib/rails/commands/console.rb:3:in `’ from /Users/rigelstpierre/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.2/lib/rails/commands.rb:38:in `require’ from /Users/rigelstpierre/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.2/lib/rails/commands.rb:38:in `’ from script/rails:6:in `require’ from script/rails:6:in `’ 有什么想法吗? Rails 3.2.2应用程序

在Ruby中区分两个XML文档?

使用?查看两个xml文件之间差异的最简单方法是什么? 我查看了Hpricot和Nokogiri,但找不到任何好的比较方法。 我也研究了像diffxml这样的unix工具,但宁愿在ruby中使用一些东西。 有人有任何想法吗?

通过Rails中的belongs_to关系查询记录

我有一个活动模型,他们属于一个位置 如何选择location.country = Australia的所有活动? (例如) 我可以在范围内执行此操作吗?

我如何使用savon嵌套属性! 哈希?

我正在考虑使用Ruby savon for SOAP。 出于纯粹的自虐原因,我必须处理具有属性的SOAP元素。 所以,没问题,savon docs网站上有一个例子突出了这个能力: { :person => “Eve”, :attributes! => { :person => { :id => 666 } } }.to_soap_xml “Eve” 我的问题是如何在子元素上设置属性,例如,我将一个地址子元素添加到person: { :person => {:address => “”}, :attributes! => { :person => { :id => 666 } } }.to_soap_xml 现在我想为地址元素添加一个id属性: 如果我在属性哈希中嵌套地址,那就不行了: { :person => {:address => “”}, :attributes! => { :person […]

ActiveRecord :: AdapterNotSpecified数据库配置未指定适配器

当我使用heroku打开我的web应用程序工作正常,但当我使用rails(localhost)时,我遇到了这个错误: ActiveRecord::AdapterNotSpecified database configuration does not specify adapter 为什么是这样? 这是我的database.yml # PostgreSQL. Versions 8.2 and up are supported. # # Install the pg driver: # gem install pg # On OS X with Homebrew: # gem install pg — –with-pg-config=/usr/local/bin/pg_config # On OS X with MacPorts: # gem install pg — –with-pg-config=/opt/local/lib/postgresql84/bin/pg_config # On Windows: […]

负索引如何与`Array# =`一起使用?

我试着看看Array#[]=是如何工作的,并且玩了: enum[int] = obj → obj enum[start, length] = obj → obj enum[range] = obj → obj 问题1 我有一个数组b在0指数处持有nil 。 b = [] b[0] # => nil 我试图在下面的代码中用整数10替换nil 。 b[-1] = 10 # => IndexError: index -1 too small for array; minimum: 0 为什么上面的代码不起作用,但下面的代码呢? 对于大小为1的数组,为什么索引0和-1处理方式不同? b[0] = 5 # => 5 b[-1] = 10 # […]

错误:无法构建gem本机扩展(ruby extconf.rb):Mac OSX

我正在尝试安装一个gem,我得到了这个错误,我自己和gem作者从未见过这个错误。 我该如何解决? Davids-MacBook-Pro:web david$ sudo /usr/bin/gem install compass –pre Password: Building native extensions. This could take a while… ERROR: Error installing compass: ERROR: Failed to build gem native extension. /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb checking for ffi.h… no checking for ffi.h in /usr/local/include,/usr/include/ffi… yes checking for ffi_call() in -lffi… yes checking for ffi_prep_closure()… yes checking for ffi_raw_call()… no […]

Rails如何从字符串地址获取纬度和经度并将其放在谷歌地图上?

这是用户故事: 用户输入地址:法国巴黎。 然后我想用一个可移动的标记在巴黎显示谷歌地图中心。 然后用户使用标记指向其确切位置并单击保存。 地址字符串和地图坐标保存到数据库中。 经过一些搜索,我知道我可以用variuos gems显示谷歌地图:例如,制图师。 我的问题是如何获取坐标或如何将地址传递给制图师,以便将其映射到巴黎?