草庐IT

iphone - POST 请求中的 & 符号造成严重破坏

全部标签

ruby - 将 Logstash 中的时间戳时区转换为输出索引名称

在我的场景中,Logstash收到的系统日志行的“时间戳”是UTC,我们在Elasticsearch输出中使用事件“时间戳”:output{elasticsearch{embedded=>falsehost=>localhostport=>9200protocol=>httpcluster=>'elasticsearch'index=>"syslog-%{+YYYY.MM.dd}"}}我的问题是,在UTC午夜,Logstash在外时区(GMT-4=>America/Montreal)结束前将日志发送到不同的索引,并且索引在20小时(晚上8点)之后没有日志,因为“时间戳”是UTC。我们已

ruby - 如何修复 RVM gem "[ missing bin/ruby ]"

执行rvmlist后,我得到以下输出:rvmrubiesgems[missingbin/ruby]=*ruby-2.0.0-p645[x86_64]ruby-2.1.6[x86_64]ruby-2.2.1[x86_64]gems[missingbin/ruby]是什么意思?gems是某种系统gemset吗?它不是我创建的,我不知道我是否可以或应该删除它。 最佳答案 在我跑完之后:rvmfix-permissions然后我能够卸载具有[缺少bin/ruby]的版本。 关于ruby-如何修复

ruby - []如何在Ruby中的类上工作

我看到我可以使用获取目录中的文件列表Dir["*"]我应该如何准确阅读该语法?据我所知,您可以使用[]从数组或散列中获取值。[]如何处理通话? 最佳答案 []只是一个方法,如#to_s、#object_id。等你可以在任何对象上定义它:classCoolClassdef[](v)puts"hello#{v}"endendCoolClass.new["John"]#=>"helloJohn"在你的情况下,它被定义为单例方法,以这种方式:classDirdefself.[](v)...endend

ruby-on-rails - Nokogiri 要求 Ruby 版本 < 2.3

我正在尝试让Rails在Windows10上运行。我正在使用Ruby2.3.0和Rails4.2.6,并且暂时使用Nokogiri1.6.3。当我尝试运行railsnewdemo时,它返回错误:Anerroroccurredwhileinstallingnokogiri(1.6.7.2),andBundlercannotcontinue.Makesurethat`geminstallnokogiri-v'1.6.7.2'`succeedsbeforebundling.当我运行geminstallnokogiri-v'1.6.7.2时,我得到:ERROR:Errorinstallingn

ruby-on-rails - 我如何比较 'Bcrypt' Gem解密的密码和加密的密码

我正在尝试对某些帖子的评论使用简单的身份验证。用户使用即时ID和密码输入评论我使用“bcrypt”gem将密码存储在数据库中。在comments_controller.rb中像这样@comment=Comment.new(comment_params)bcrypted_pwd=BCrypt::Password.create(@comment.user_pwd)@comment.user_pwd=bcrypted_pwd当用户想要删除他们的评论时,我使用data-confirm-modalgem来确认数据在这部分,我必须解密用户输入的密码以与数据库中的加密密码进行比较我怎样才能解密密码,

ruby-on-rails - "undefined method ` stub_request '"访问 RSpec 支持文件中的方法时

我的Ruby-on-Rails项目中有以下文件结构,用于规范:/spec/msd/serviceservice_spec.rb/support/my_modulerequests_stubs.rb我的request_stubs.rb有:moduleMyModule::RequestsStubsmodule_functiondeflist_clientsurl="dummysite.com/clients"stub_request(:get,url).to_return(status:200,body:"clientsbody")endend在我的service_spec.rb我有:re

ruby-on-rails - 以 DRY 方式覆盖 ActiveRecord 中的 "find"

我有一些模型需要在它们上面放置自定义查找条件。例如,如果我有一个联系人模型,每次调用Contact.find时,我都想限制返回的联系人只属于正在使用的帐户。我通过Google找到了这个(我对其进行了一些自定义):defself.find(*args)with_scope(:find=>{:conditions=>"account_id=#{$account.id}"})dosuper(*args)endend这很好用,除了少数情况下account_id不明确,所以我将其调整为:defself.find(*args)with_scope(:find=>{:conditions=>"#{s

ruby - 模块中的 instance_eval 与 class_eval

classFooincludeModule.new{class_eval"deflab;puts'm'end"}deflabsuperputs'c'endendFoo.new.lab#=>mc======================================================================classFooincludeModule.new{instance_eval"deflab;puts'm'end"}deflabsuperputs'c'endend注意这里我把class_eval改成了instance_evalFoo.new.labresc

ruby-on-rails - 像 "has_one"这样的 Rails 方法调用是如何工作的?

我是PHP开发人员,目前我正在学习Rails(3),当然还有Ruby。Idon'twanttobelieveinmagic因此,我尽可能多地了解Rails“背后”发生的事情。我发现有趣的是ActiveRecord模型中的方法调用,如has_one或belongs_to。我试图重现它,并提供了一个天真的例子:#has_one_test_1.rbmoduleFooclassBasedefself.has_oneputs'Willitwork?'endendendclassModel2如我所料,只要运行这个文件就会输出“Willitwork?”。在搜索Rails源代码时,我找到了负责的函数:

ruby - 数组数组中的唯一元素

我想通过内部数组中的第一个元素从数组数组中找到唯一元素。例如a=[[1,2],[2,3],[1,5]我想要类似的东西[[1,2],[2,3]] 最佳答案 uniq方法需要一个block:uniq_a=a.uniq(&:first)或者如果您想就地进行:a.uniq!(&:first)例如:>>a=[[1,2],[2,3],[1,5]]=>[[1,2],[2,3],[1,5]]>>a.uniq(&:first)=>[[1,2],[2,3]]>>a=>[[1,2],[2,3],[1,5]]或者>>a=[[1,2],[2,3],[1,5]