草庐IT

updated_date

全部标签

ruby - 导轨 : seeding database data and date formats

我正在尝试使用db/seed.rb文件和rakedb:seed命令将一些数据播种到我正在开发的Rails3应用程序中。我播种的数据涉及一个名为Meeting的数据库表,该表具有三列:字符串标题、日期时间开始日期、日期时间结束日期。我尝试插入的日期时间采用“mm/dd/yyyyhh:mm”格式——例如。“01/02/200313:23”=2003年1月2日下午1:23。但是,DateTime.parse()始终会出现“无效日期”错误——因为它试图以“dd/mm/yyyy”格式解析日期。根据我的谷歌搜索,我被引导相信在解析DateTime对象时,编译器会查看传入的字符串并进行一些仓促的模式

ruby - update(other_hash) 和 merge(other_hash) 的区别

更新代码:irb(main):001:0>h1={"a"=>100,"b"=>200}=>{"a"=>100,"b"=>200}irb(main):002:0>h2={"b"=>254,"c"=>300}=>{"b"=>254,"c"=>300}irb(main):003:0>h1.update(h2)=>{"a"=>100,"b"=>254,"c"=>300}合并代码:irb(main):001:0>h1={"a"=>100,"b"=>200}=>{"a"=>100,"b"=>200}irb(main):002:0>h2={"b"=>254,"c"=>300}=>{"b"=>254,

ruby-on-rails - 在 Rails 3 中使用 update_columns?

在Rails3中有更短的方法吗?user.update_column(:attribute1,value1)user.update_column(:attribute2,value2)user.update_column(:attribute3,value3)user.update_column(:attribute4,value4)我试过update_columns但它只在Rails4中可用。感谢您的帮助。 最佳答案 这是Rails3.x的解决方法:User.where(id:user.id).update_all(attribu

ruby - 在 Ruby 中,为什么等于 nil ("Date.new == nil") 返回 nil?

今天写一些rspec时,我遇到了一些意外的行为,将日期(和时间)实例与nil进行比较。这是一个使用原始ruby​​的示例(没有Rails或其他库):user@MacBook-Work~$ruby-vruby1.8.7(2008-08-11patchlevel72)[universal-darwin10.0]user@MacBook-Work~$irb>>1==nil=>false>>"string"==nil=>false>>:sym==nil=>false>>false==nil=>false>>[]==nil=>false>>{}==nil=>false>>Proc.new{}==

ruby-on-rails - 使用#update_all 更新时间戳

当我有要更新其属性的ID列表时,数据库中的updated_at字段似乎没有改变,这就是我的意思:ids=[2,4,51,124,33]MyObj.where(:id=>ids).update_all(:closed=>true)执行此更新后,updated_at字段不会更改。但是,当我使用railsc进入rails控制台并执行此操作时:obj=MyObj.find(2)obj.closed=false;obj.save!在此语句之后updated_at字段更改值。为什么是这样?当发生这种情况时,我正在监听更新并执行整个应用程序流程时,我依赖于我的应用程序中的这个updated_at字段

ruby-on-rails - Date 与 ActiveSupport::TimeWithZone 的比较失败

我的Waiver模型上有一个age方法,如下所示:defage(date=nil)ifdate.nil?date=Date.todayendage=0unlessdate_of_birth.nil?age=date.year-date_of_birth.yearage-=1ifdate然后我有一个看起来像这样的规范:it"calculatestheproperage"dowaiver=FactoryGirl.create(:waiver,date_of_birth:12.years.ago)waiver.age.should==12end当我运行这个规范时,我得到Comparisono

ruby-on-rails - 尝试更新数据库值时,rails update_attributes 返回 false

希望这里有人能给我指出正确的方向。我有一个ControllerUpdatedef运行“update_attributes”。目前它返回false,没有错误消息。我是Ruby的新手,但不是编码的新手,这让我困惑了好几天!我正在尝试使用下面指定的值更新用户模型和数据库。defupdate#getcurrentlyloggedinuser@user=current_user#updateuserparamsbasedoneditform...if@user.update_attributes(params[:user])redirect_toprofile_path,:notice=>"Su

ruby - 使 Date#parse 采用美国格式而不是欧盟格式

在1.9.2p0中,Date#parse采用UE格式。如果您不相信我,请查看format.rb,第1042行。无论如何,我怎样才能让它采用美国格式,以便:>Date.parse("10/4/2010")=>Mon,04Oct2010而不是4月10日。我已经试过了:classDatedef_parse_eu(str,e)_parse_us(str,e)endend但运气不好。还有其他想法吗? 最佳答案 Date.strptime是你想要的但不幸的是它看起来不像文档有日期格式字符串。我得到以下基于格式字符串的谷歌搜索的工作:1.9.2>

ruby - 为什么 Date 在需要之前就存在于 Ruby 中?

在Ruby中,我希望一个不需要的类会引发“未初始化常量”错误。例如,CSV就是这种情况。但是,Date的行为很奇怪:它可用,但显然不起作用,直到需要它为止。~:irb>>Date.new(2012,7,24)ArgumentError:wrongnumberofarguments(3for0)>>require'date'=>true>>Date.new(2012,7,24)=>#如何解释这种行为? 最佳答案 我相信date不是来自irb,而是来自rubygems,特别是thefile其中定义了Gem::Specification:

关于Document mapping type name can‘t start with ‘_‘, found: [_update]

在修改elasticsearch时,用_update进行局部修改,修改失败,报错{    "error": {        "root_cause": [            {                "type": "invalid_type_name_exception",                "reason": "Document mapping type name can't start with '_', found: [_update]"            }        ],        "type": "invalid_type_name_exce