草庐IT

order_datetime

全部标签

ruby - 为什么 Test::Unit.test_order= 没有按预期工作?

有问题InRuby,howtoIcontroltheorderinwhichTest::Unittestsarerun?并想引用test_order=:defined,来回答documentationforTest::Unit::TestCase.test_order说:Setsthecurrenttestorder.Herearetheavailableorder::alphabeticDefault.Testsaresortedinalphabeticorder.:randomTestsaresortedinrandomorder.:definedTestsaresortedind

ruby - 导轨 : control ordering of query parameters in url_for?

我想生成一个URL,其中“p=1”查询参数出现在URL的末尾,例如:/path?foo=X&bar=Y&p=1生成URL时是否可以控制查询参数的顺序:url_for(params.merge({p:page_num}))?更新:我试过了ChuckE'ssuggestionbelow.事实证明,在Ruby1.9中,哈希已经排序,因此ActiveSupport::OrderedHash中的代码实际上是空操作。您可以使用Ruby1.9验证顺序是否已保留:>>h={one:1,two:2,three:3}{:one=>1,:two=>2,:three=>3}>>f=h.except(:one)

ruby-on-rails - 错误 : SELECT DISTINCT ON expressions must match initial ORDER BY expressions

我的要求是得到不同的记录并按顺序User.joins('INNERJOINreport_postsONposts.id=report_posts.post_id').select('DISTINCTON(report_posts.post_id)posts.idasreport_posts.idasreported_id,report_posts.reported_at').order('report_posts.reported_atdesc')我知道这在postgresql中是不可能的,我已经读过这个PostgresqlDISTINCTONwithdifferentORDERBY我

ruby - 从 UTC 秒数创建 DateTime

我不敢相信我在任何地方都找不到这个,但是你怎么能从UTC秒创建一个DateTime?类似于在Java中,您可以通过Calendar.getInstance().setTimeInMillis(time)获取特定时间。DateTime.new1344899588没有工作,我在DateTimeAPI文档中没有看到任何说明如何执行此操作的内容。这行得通,但似乎是一种迂回的方式:DateTime.strptime(1344899588.to_s,"%s") 最佳答案 您可以为此使用Time类,即t=Time.at(1344899588)如果

ruby - 如何从 Ruby 中的 DateTime 中减去 n 个月?

我是ruby​​的新手,日期算术看起来很困惑。如何在不使用任何其他模块的情况下从DateTime中删除n个月? 最佳答案 自DateTime是Date的子类,你可以使用或prev_month:require'date'd=DateTime.now#=>#d#d.prev_month(4)#=>#请注意DateTime不考虑夏令时。 关于ruby-如何从Ruby中的DateTime中减去n个月?,我们在StackOverflow上找到一个类似的问题: https

ruby-on-rails - Group by 和 order by 在 Rails 中有很多直通模型

您好,我已经搜索过了,但还没有找到执行此操作的方法我有以下模型:classHierarchy.classFamily:hierarchiesend.classUser:hierarchiesend有了current_user,我需要获取他的所有其他家庭成员,按级别分组,然后按列顺序排序。我会说出我尝试过的,但实际上并没有那么多,而且这个查询超出了我的能力范围。我正在使用postgres。 最佳答案 我会采用以下方法..我们必须更新用户模型:)classUser:hierarchieshas_many:family_members,-

ruby-on-rails - rails : Order a model by the last element of a has_many association

我有两个模型:User和Message,它们通过has_many关系连接。我想获得一个users列表,按他们上一条消息的时间戳排序。classUser当我这样做时:@users=User.includes(:messages).order('messages.created_atDESC').limit(5)它似乎对消息进行排序,获取最新的5条消息,然后返回与这些消息关联的用户。所以用户数可以少于5个。我想确保获得5个用户。我希望查询为每个请求获取最新消息,对最后的消息进行排序,然后将最新消息返回给用户。所以我想要这样的东西:@users=User.includes(:messages

ruby - Podio:设置 DateTime 字段值时使用哪个时区

使用跑道API创建新项目或更新现有项目时,将DateTime字段值设置为:2016-10-2114:15:00(例如)。将使用哪个时区来存储此DateTime?例如要求:app_id=content={'title'=>'Datesetto"14:15"','date'=>{'start'=>'2016-10-2114:15:00','end'=>'2016-10-2115:00:00'}}item=Podio::Item.create(app_id,'fields'=>content)结果:'start_date_utc'=>2016-10-21'end'=>2016-10-2115

ruby - rspec - 如何与预期中的实际 DateTime 进行比较?

我的rspec:it"canshowthecurrentmonthname"doexpect(Calendar.create_date_using_month(1)).toeq'2000-01-0100:00:00-0500'end失败:expected:"2000-01-0100:00:00-0500"got:2000-01-0100:00:00-0500对于我的代码:defself.create_date_using_month(n)Time.new(2000,n,1)end我应该/可以更改RSpec以便与实际字符串而不是日期进行比较吗?我试过:Date.strptime("{20

ruby /事件记录 : custom sorting order

我正在开发一个Rails3.2ruby​​1.9.2项目。我从经典数据库中获取了一些值:designators=Model.find()我用(简化代码)显示它:">值例如:3L、3C、3R。(L代表左,C代表中心,4代表右)。我想要订购的值,例如:3L、3C、3R而不是3C、3L、3R我不知道如何定义这个自定义顺序。有什么想法吗? 最佳答案 尝试这样的事情:(app/models/designator.rb)#determinesthesortvalueforbasedonmy_attribute.#designatorsshoul