jjzjj

datetime-local

全部标签

ruby-on-rails - postgresql 数据库错误 : Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

当我运行rakedb:migrate或运行railss命令时,我得到同样的错误:Error:couldnotconnecttoserver:NosuchfileordirectoryIstheserverrunninglocallyandacceptingconnectionsonUnixdomainsocket"/var/run/postgresql/.s.PGSQL.5432"?当我尝试railss时,浏览器出现错误。这是我的database.ymldefault:&defaultadapter:postgresqlencoding:unicodepool:5development

ruby-on-rails - 如何在 Rails 中将随机 DateTime 四舍五入到小时开始?

基本上我想在去年获得一个随机日期时间:rand(1.year).ago#=>Sun,22Sep201318:37:44UTC+00:00(example)但是我该如何指定或限制在整点时间呢?例如:Sun,22Sep201318:00:00UTC+00:00Sat,02Nov201310:00:00UTC+00:00Fri,12Apr201321:00:00UTC+00:00 最佳答案 我终于找到了我要找的东西。@Stoic的回答很好,但我找到了这个可用的方法(http://api.rubyonrails.org/classes/Da

ruby - bundler 的可执行文件 "bundle"与/usr/local/bin/bundle 冲突 覆盖可执行文件?

当我安装jekyllbundle并输入命令geminstalljekyllbundler时。终端弹出bundler的可执行文件“bundle”与/usr/local/bin/bundle冲突的消息覆盖可执行文件? 最佳答案 在我的例子中,我必须覆盖/usr/local/bin/bundle和/usr/local/bin/bundler才能成功安装bundler-1.16.6.否则,在运行jekyllnewwebsitedir时,会出现以下消息的错误。Bundler:ruby:Nosuchfileordirectory--/usr/l

ruby-on-rails - 我什么时候应该在 ruby​​/rails 中使用 DateTime 与日期、时间字段?

我目前有单独的game_date和game_time字段,由于时区问题,我很难将我的DateTime.now与串联的DateTime进行比较。我应该重新设计我的数据库以仅使用DateTime吗?我单独有一个时间字段,因为时间在某些时间点可以为NULL。通常的做法是什么,以及我应该如何解决以下时区的问题?now=DateTime.now@upcoming_games=[]@past_games=[]games.eachdo|game|game.game_time=DateTime.nowifgame.game_time.nil?dt=DateTime.parse("#{game.game

ruby-on-rails - Rails 中至少有 2 个 DateTime?

如何在Rails中找到2个DateTime对象中的最小值? 最佳答案 最rubyish的方式是使用[a,b].min但你也可以使用C风格(a>b)?b:a希望这对您有所帮助! 关于ruby-on-rails-Rails中至少有2个DateTime?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/5071334/

ruby-on-rails - 如何检查是否存在值不为 "undefined local variable or method"的变量?

这是一个常见的模式:如果变量不存在,我会得到一个未定义的局部变量或方法错误。现有代码有ifvariable_name.present?但这并没有说明变量不存在。我如何检查变量的值并说明它根本不存在?我试过:if(defined?mmm)thenifmmm.present?thenputs"true"endend但Ruby仍然检查内部mmm.present?并在它不存在时抛出“nosuchvariable”。我确信对此有一个共同的模式/解决方案。 最佳答案 将present?更改为!=''并使用&&运算符,它仅在第一个表达式为真时才尝

ruby - DateTime.strptime 我做错了什么?

当我这样做时,我的ruby​​程序说我的日期无效:format="%D/%M/%Y%H:%M:%S:3N"date="21/03/201116:39:11.642"DateTime.strptime(time,format)这个我也试过:format="%D/%M/%Y%H:%M:%S:3"我得到的是这个:ArgumentError:invaliddatefrom/usr/local/lib/ruby/1.9.1/date.rb:1688:in`new_by_frags'from/usr/local/lib/ruby/1.9.1/date.rb:1713:in`strptime'fro

ruby - 你如何让 DateTime.parse 返回你所在时区的时间?

我需要这个require'date'DateTime.parse"Mon,Dec276:30pm"返回EDT时区下午6:30的DateTime,但返回UTC时间。如何获取EST日期时间或将UTC日期时间转换为具有下午6:30值的EDT日期时间? 最佳答案 好的,我要回答我自己的问题require'time'ENV["TZ"]="US/Eastern"Time.parse("Mon,Dec276:30pm").to_datetime=># 关于ruby-你如何让DateTime.parse

ruby-on-rails - 将 ActiveSupport::TimeWithZone 转换为 DateTime

我试图在两个日期之间每隔N天步进一次。我尝试了以下代码,但没有用,因为startDate和endDate是ActiveSupport::TimeWithZone对象,而不是我想的DateTime对象。startDate.step(endDate,step=7){|d|putsd.to_s}min.step(max,step=stepInt){|d|putsd.to_s}如何将TimeWithZone对象转换为DateTime? 最佳答案 我认为更新这个答案可能会有用,因为我最近在搜索这个。实现此转换的最简单方法是使用.to_date

ruby - Pry Error : Cannot find local context. 您是否使用了 `binding.pry`?

为什么我会收到此pry动错误?[36]pry(main)>s="pry"Error:Cannotfindlocalcontext.Didyouuse`binding.pry`?在此截屏视频中运行良好http://pryrepl.org/ 最佳答案 似乎s、c和n是pry-navgem上的保留命令,发现here,这可以帮助您逐步完成绑定(bind)。Pry.commands.alias_command'c','continue'Pry.commands.alias_command's','step'Pry.commands.alias