任何类似教程的文章都解释了如何在Android上使用jRuby?

我打算购买一部Android手机,并希望能够在Ruby上编写一些简单的应用程序。 我在8月份发现了这篇文章,作者能够使脚本正常工作,但由于我不是Java主管,所以我很难理解所有步骤。 http://amazing-development.com/archives/2009/08/04/android-scripting-environment-supports-jruby/ 您是否知道其他任何教程或如何更详细地解释该过程? 你知道自8月以来表现是否有所改善?

Rails Edge / 4“require”出错:无法加载此类文件 – thread_safe

按照这里的说明获取运行Rails Edge的应用程序来测试Rails 4: 使用edge生成Rails应用程序的最佳方法是什么? 以及如何创建Edge rails应用程序? 但遇到这个错误: `require’: cannot load such file — thread_safe (LoadError) 使用命令: rails new Edge –edge –skip-bundle –database=postgresql –skip-test-unit –skip-index-html 我的路径上有一个Rails master bin dir的结帐。 我使用rbenv与ruby 1.9.3p327。 我已经清除了所有已安装的gem,只是运行了捆绑器。 Rails 3.2.9在我的系统上工作正常,有一个正在开发的应用程序。

用自定义图像替换破碎的外部图像

我正在遍历在外部站点托管的一系列URL图像字符串。 它看起来像这样: def get_image_urls image_url_array.each do |image_url| puts image_tag image_url end end 这将返回外部站点上托管的图像的URL。 问题是,其中一些图像可能会被破坏(404)。 例如: get_image_urls # These would return image_tags, but for brevity… => “http://sofzh.miximages.com/ruby-on-rails/1.jpg” “http://sofzh.miximages.com/ruby-on-rails/2.jpg” “http://sofzh.miximages.com/ruby-on-rails/3.jpg” # <– (Broken: 404) "http://sofzh.miximages.com/ruby-on-rails/4.jpg" "http://sofzh.miximages.com/ruby-on-rails/5.jpg" # <– (Broken: 404) 我要做的是将损坏图像的URL字符串替换为我自己网站上托管的“缺失”图像。 所以使用上面的例子,3.jpg和5.jpg被打破了,我想要返回这样的东西: get_image_urls # These would return image_tags, but for brevity… => “http://sofzh.miximages.com/ruby-on-rails/1.jpg” “http://sofzh.miximages.com/ruby-on-rails/2.jpg” “http://mysite.com/images/missing.png” “http://sofzh.miximages.com/ruby-on-rails/4.jpg” “http://mysite.com/images/missing.png” […]

将XPath与HTML或XML片段一起使用?

我是Nokogiri和XPath的新手,我试图访问HTML或XML片段中的所有注释。 当我没有使用fragment函数时,XPaths .//comment()和//comment()工作,但是他们找不到任何片段。 使用标记而不是注释,它适用于第一个XPath。 通过反复试验,我意识到在这种情况下, comment()只找到顶级注释和.//comment()而其他一些只找到内部注释。 难道我做错了什么? 我错过了什么? 任何人都可以解释发生了什么? 我应该使用什么XPath来获取Nokogiri解析的HTML片段中的所有注释? 这个例子可以帮助理解这个问题: str = “” # this works: Nokogiri::HTML(str).xpath(“//comment()”) => [#, #] Nokogiri::HTML(str).xpath(“.//comment()”) => [#, #] # with fragment, it does not work: Nokogiri::HTML.fragment(str).xpath(“//comment()”) => [] Nokogiri::HTML.fragment(str).xpath(“comment()”) => [#] Nokogiri::HTML.fragment(str).xpath(“.//comment()”) => [#] Nokogiri::HTML.fragment(str).xpath(“*//comment()”) => [#] Nokogiri::HTML.fragment(str).xpath(“*/comment()”) => [#] # however it does if it is a […]

在PostgreSQL 9.3上安装PL / Ruby

我想使用PL / Ruby过程语言,但似乎git存储库维护得不是很好: https : //github.com/Absolight/postgresql-plruby/tree/fixup-9-3 当我开始创建新语言时: create function plruby_call_handler() returns language_handler as ‘/var/lib/postgresql/.rvm/rubies/ruby-2.1.3/lib/ruby/site_ruby/2.1.0/x86_64-linux/plruby’ language ‘c’; — Warning: the ‘c’ has to be lowercase, unlike the example on git. 我收到以下错误: ERROR: could not load library “/var/lib/postgresql[…]plruby”: undefined symbol: plruby_s_load 我在Ubuntu 14.10上使用Ruby 2.1.4和PostgreSQL 9.3。

ruby没有加载font-awesome

我正在尝试将font-awesome加载到我的视图中 我已经阅读了其他答案并实现了Rails:使用Font Awesome 我做了什么 配置/ application.rb中 require File.expand_path(‘../boot’, __FILE__) require ‘rails/all’ # Require the gems listed in Gemfile, including any gems # you’ve limited to :test, :development, or :production. Bundler.require(:default, Rails.env) module Blog class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in […]

Ruby,堆栈级别太深(SystemStackError)

我有以下代码: class BookPrice attr_accessor :price def initialize(price) @price = price end def price_in_cents Integer(price*100 + 0.5) end end b = BookPrice.new(2.20) puts b.price_in_cents 这一切都运作良好,产生220.但当我更换第二行attr_accessor:价格与: def price @price = price end 我的堆栈级别太深(SystemStackError)错误。 这是怎么回事? 我知道我可以用@price替换Integer(价格* 100 + 0.5)而不是方法调用价格,但是我想保持它与OOP原因的方式。 如何在没有attr_accessor的情况下使这段代码按原样运行?

导轨 – 在导轨中找到条件4

我最近将我的rails升级到Rails 4.1.6。 此查询用于工作: @user = User.find(:all, :conditions => { :name => ‘batman’ }) 现在我收到此错误消息: Couldn’t find all Users with ‘id’: (all, {:conditions=>{:name=>”batman”}}) (found 0 results, but was looking for 2) 当我检查日志时,我可以看到rails正在尝试执行完全不同的查询: User Load (0.4ms) SELECT “users”.* FROM “users” WHERE “users”.”id” IN (‘all’, ‘— :conditions: :name: batman ‘) 看起来,它试图让所有用户都拥有ID“all”和“{:conditions => {:name =>”batman“}}”。 请帮忙。 更新: 我背后真正的问题是我想要一个特定的用户并添加他的汽车,只有蓝色的汽车。 例如,这是我的查询,用户ID是20。 […]

如何在Ruby中迭代部分哈希?

h = Hash.new (1..100).each { |v| h.store(v * 2, v*v) } 在不使用密钥的情况下迭代哈希的给定部分的最佳方法是什么? 例如,从元素10到元素20? 使用Ruby 1.9.3。 编辑 – 回应戴夫的评论: 最初我想通过密钥访问数据(因此哈希)。 但我也想按元素编号进行迭代。 顺便说一句,每个元素都是一个哈希。 那么,设计散列哈希值或哈希数组的最佳方法是什么,可以通过元素号迭代或通过键访问? 数据如下所示。 缺少日期。 6/23/2011 – > 5,6,8,3,6 6/26/2011 – > 6,8,4,8,5 6/27/2011 – > 8,4,3,2,7

ruby – 简化字符串乘法串联

s是一个字符串,这看起来很啰嗦 – 我怎样才能简化这个? : if x === 2 z = s elsif x === 3 z = s+s elsif x === 4 z = s+s+s elsif x === 5 z = s+s+s+s elsif x === 6 z = s+s+s+s+s 谢谢