草庐IT

ruby-on-rails - Ruby/Rails - 检查 HABTM 关系记录中是否存在子 ID

我有一组名为Tasks和Posts的资源,它们之间存在has_and_belongs_to_many(HABTM)关系。还有一个连接它们的值的连接表。create_table'posts_tasks',:id=>falsedo|t|t.column:post_id,:integert.column:task_id,:integerend所以我的问题是如何检查特定任务的ID是否存在于从@post.tasks创建的数组中?irb(main):011:0>@post=Post.find(1)=>#@post.tasks=>[#,#]所以我的问题是,@post.tasks中是否存在"@task

ruby - 无法在 Mac 上设置 ruby​​-selenium Webdriver

我一直在工作中使用seleniumIDE。现在我们决定将Seleniumwebdriver与Ruby结合使用。我完全不知道如何设置我的Mac,MacProYosemite10.10.5。在我的终端中,我运行了这些命令:$ruby-e"$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/install)"$brewdoctorYoursystemisreadytobrew.$brewinstallruby==>Summary/usr/local/Cellar/openssl/1.0.2d_1:464fi

ruby-on-rails - 内存中具有相同 ID 的更多对象?

在部署在heroku上的Rails应用程序(v:3.1)中,我在内存中获得了更多具有相同ID的对象。我的heroku控制台日志:>>Project.find_all_by_id(92).size=>2>>ActiveRecord::Base.connection.execute('select*fromprojectswhereid=92').to_a.size=>1这怎么可能?可能是什么问题? 最佳答案 解决方案根据您的SQL查询,您的数据库中显然没有重复条目。也许您的类项目中的size或length方法已被覆盖。我试过find_

ruby - 如何通过 belongs_to 按外部 id 和本地属性进行过滤?

以下模型通过belongs_to链接:require'mongoid'classSensorincludeMongoid::Documentfield:sensor_id,type:Stringvalidates_uniqueness_of:sensor_idend...require'mongoid'require_relative'sensor.rb'classSensorDataincludeMongoid::Documentbelongs_to:sensorfield:date,type:Datefield:ozonMax1h,type:Floatfield:ozonMax8h

ruby - 在我的 Mac 上安装 ruby​​ gem json 时遇到问题

我在尝试通过ruby​​gems安装json模块时收到此警告。有什么想法吗?Mac-Minipoulh$sudogeminstalljsonPassword:WARNING:File'/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/specifications/json-1.2.0.gemspec'doesnotevaluatetoagemspecificationBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errori

ruby - 在 Mac OS Lion 上安装 Ruby 1.9.2 时出现问题

我正在运行Lion,使用Xcode4,安装了RVM和自制软件,但我只能运行ruby​​1.8.7spurvis:~rogue$ruby-vruby1.8.7(2010-01-10patchlevel249)[universal-darwin11.0]spurvis:~rogue$我已经通读了几个与该主题相关的线程,但似乎没有任何方法可以解决我的问题:spurvis:~rogue$rvminstall1.9.2InstallingRubyfromsourceto:/Users/rogue/.rvm/rubies/ruby-1.9.2-p290,thismaytakeawhiledepen

ruby-on-rails - 如果我有一个来自收费的 Stripe token ,我如何获得它的收费 ID?

现在我正在使用我的Rails应用程序成功收费,但我想获取有关交易的某些详细信息,例如商品购买的描述和信用卡的最后四位数字,以显示给用户他们的收据页面。我一直在查看文档,但实际上没有任何内容可以解释如何为应用提供token并取回charge_id,然后我可以使用它来获取有关费用的其他信息的哈希值。任何帮助都是巨大的。谢谢! 最佳答案 Stripe在对费用创建调用的响应中返回费用ID。如果您使用的是Ruby库,则可以执行以下操作来获取ID:require"stripe"Stripe.api_key=''charge=Stripe::Ch

ruby - 为什么 openssl 在 windows 上产生错误但在 centos 上不产生错误:PKCS12_parse: mac verify failure (OpenSSL::PKCS12::PKCS12Error)

require'openssl'ifARGV.length==2pkcs12=OpenSSL::PKCS12.new(File.read(ARGV[0]),ARGV[1])ppkcs12.certificateelseputs"Usage:load_cert.rb"end运行它会在Windows上产生错误,但在Linux上不会。错误:OpenSSL::PKCS12::PKCS12Error:PKCS12_parse:macverifyfailurefrom(irb):21:ininitializefrom(irb):21:innewfrom(irb):21fromC:/Ruby192/

ruby-on-rails - 在 Mac OS 上安装 Rails 失败并出现多个错误

我正在尝试在我的MacOSv10.10.4系统上安装Rails,但当我运行brewinstallrbenvruby​​-build时它失败了。错误是:Error:Permissiondenied-/usr/local/etc/opensslWarning:Bottleinstallationfailed:buildingfromsource.在过程结束时它说:installingman3/d2i_SSL_SESSION.3ssli2d_SSL_SESSION.3ssl=>d2i_SSL_SESSION.3sslinstallingman3/ssl.3sslCannotcreatedir

ruby - ActiveRecords 选择(:id). 收集与采摘(:id) methods: Why is pure AR "pluck" slower?

我正在尝试从我的文章模型中获取所有ID。我可以通过两种方式做到这一点:Article.select(:id).collect{|a|a.id}ArticleLoad(2.6ms)SELECT"articles"."id"FROM"articles"或2.2.1:006>Article.pluck(:id)(4.3ms)SELECT"articles"."id"FROM"articles"什么给了?为什么AR比Ruby版本慢?即使我对Ruby方法进行基准测试,它似乎也更快:Benchmark.measure{Article.select(:id).collect{|a|a.id}}Art