草庐IT

time_of_last_update

全部标签

Ruby Time#to_date() 方法返回错误的日期

我们使用的是Ruby1.9.3,我发现Time#to_date似乎是一个奇怪的Ruby错误Time.new(1).to_date在应返回0001年1月1日时返回0001年1月3日。我无意中发现了这个问题。似乎如果我调用.to_datetime.to_date,结果是正确的。我还发现了一些其他相关的怪异之处。请参阅下面的irb控制台输出。(请注意,我使用的是irb,而不是railsconsole,以确保我使用的只是Ruby,不是Rails的任何附加内容。)>>require"Time"=>true>>Time.new(1).to_date=>#>>Time.new(1).to_datet

ruby - 类型错误 : no implicit conversion of Hash into String

尝试解析一些JSON,为什么text是空的?期望的输出:text应该返回Helloworld\n\nApple,Harbor\n\nBanana,Kitchen\n\nMango,Bedroomtext="Helloworld"json='{"fruits":[{"name":"Apple","location":"Harbor"},{"name":"Banana","location":"Kitchen"},{"name":"Mango","location":"Bedroom"}]}'fruits=JSON.parse(json)defformat_fruits(fruits)fr

ruby - 使用 Time.zone 使用 strptime 解析时间

我正在尝试使用Ruby2.0中的Time类解析日期时间。我不知道如何解析日期并在指定时区获取它。我使用Time.zone.parse解析我第一次调用Time.zone的日期并将其设置为指定时区。在下面的示例中,我设置了区域但它不影响strptime,我已经尝试执行Time.zone.parse(date)但我无法解析它如下所示的日期。Time.zone="CentralTime(US&Canada)"#=>"CentralTime(US&Canada)"irb(main):086:0>Time.strptime("08/26/201303:30PM","%m/%d/%Y%I:%M%p"

Ruby - 创建 gem : reload console with updated gem content

根据这个article,我们可以通过将这些行添加到我们的rakefile来测试我们的gem代码:​​task:consoledorequire'irb'require'irb/completion'require'my_gem'#Youknowwhattodo.ARGV.clearIRB.startend它工作得很好,只是每当对gem进行更改时,我都需要退出并重新运行rakeconsole以更新代码。作为创建/调试工具确实不方便...有没有一种方法可以编写一个自定义方法来充当Rails中很棒的reload!方法?bash脚本不会工作,因为第一个命令在Ruby控制台中,我宁愿有一个100

ruby - ActiveJob::SerializationError - 不支持的参数类型:Time/DateTime

我正在使用Rails5和ActiveJob来处理后台任务。我正在尝试将使用as_json序列化的对象传递给我的工作,但我收到以下错误:ActiveJob::SerializationError(Unsupportedargumenttype:Time):ActiveJob::SerializationError(Unsupportedargumenttype:DateTime):我知道ActiveJob不会接受Time/DateTime对象,因为一些排队系统不处理这些类型。所以我要序列化的对象如下:card=Card.first=>#当我运行时:card.as_json=>{"id"=

ruby-on-rails - rails : :inverse_of and Association extensions

我有以下设置classPlayer:playerdodefin_handfind_all_by_location('hand')endendendclassCard:cardsend这意味着以下工作:p=Player.find(:first)c=p.cards[0]p.score#=>2c.player.score#=>2p.score+=1c.player.score#=>3c.player.score+=2p.score#=>5但下面的行为不一样:p=Player.find(:first)c=p.cards.in_hand[0]p.score#=>2c.player.score#=

git submodule update --init --recursive 父子仓库

.gitmodules:记录子模块信息在父项目新建submodule添加:gitsubmoduleadd 子模块仓库地址  子模块在父模块目录下的存储路径。注意:路径不能以/结尾(会造成修改不生效)、不能是现有工程已有的目录(不能順利Clone)删除:首先删除.gitmodules文件下的对应子模块信息,然后 gitrm–cached 克隆下来的项目有submodule拉取submodule: gitsubmoduleupdate--init--recursive更新submodulegitsubmoduleupdate--remote或者在submodule打开gitbash,然后用gitp

ruby-on-rails - "gem update --system is disabled on Debian"错误

当我尝试更新ruby​​gems(通过运行“gemupdate--system”)时出现此错误:ERROR:Whileexecutinggem...(RuntimeError)gemupdate--systemisdisabledonDebian.RubyGemscanbeupdatedusingtheofficialDebianrepositoriesbyaptitudeorapt-get.知道可能出了什么问题以及如何解决它吗? 最佳答案 有两种方法:摆脱debianruby​​包并从源代码安装ruby​​,或者您可以按照给您的说

ruby - 时间 :Class after requiring active_support/time_with_zone 的未定义方法 `zone`

我在使用Ruby2.2.1并安装了active_support4.2,所以我想使用Time.zone.parse('2007-02-1015:30:45')如此处所述:http://api.rubyonrails.org/classes/ActiveSupport/TimeWithZone.html但即使在需要active_support和active_support/time_with_zone之后,我觉得Time.zone仍然不起作用。观察:2.2.1:002>require"active_support"=>true2.2.1:003>Time.zoneNoMethodError

ruby-on-rails - Capistrano 部署 :migrate and db:migrate run all migrations every time

因此,我正在使用rails(ruby1.9.3p392、rails3.2、sqlite3db)并尝试将无处不在的博客教程代码部署到“生产”服务器(apache、passenger、ubuntu)。我的deploy.rb看起来像这样:require'bundler/capistrano'require'rvm/capistrano'load'deploy/assets'set:rvm_ruby_string,ENV['GEM_HOME'].gsub(/.*\//,"")set:rvm_type,:userset:user,'blah'set:application,'railsTest'