草庐IT

assignment_date

全部标签

ruby-on-rails - Date.new 为 `div' :String 返回未定义的方法 "11"

我遇到了错误undefinedmethod`div'for"11":String"在我提交表单时指向@startdate行。我完全不明白这是怎么回事。如果我在Rails控制台中执行这些步骤,它就可以正常工作。在我的Controller中我有:@startday=params["startday_#{i}".to_sym]@startmonth=params["startmonth_#{i}".to_sym]@startyear=params["startyear_#{i}".to_sym].to_s@endday=params["endday_#{i}".to_sym]@endmont

ruby-on-rails - rails : Human-friendly date format for text_field

我有一个存储为日期时间值的birth_date字段。默认的railsformhelpers吐出一种不太友好的格式,例如“2008-06-1022:33:19.000000”。下面是Vanillarails方式。"20"%>我怎样才能简单地应用一种格式?我尝试了各种方法,例如strftime应该可以,我想。但是当我尝试以下操作时,出现错误undefinedmethod'strftime'fornil:NilClassf.object.birth_date.strftime('%m/%d/%Y'),:size=>"20"%>根据其他一些问题/答案,我尝试了以下方法。它适用于非空值,但它是丑

ruby-on-rails - Rails 3/Ruby 1.9.2 Date.tomorrow 不正确

在MacSnowleopard上使用Ruby1.9.2和Rail3ruby-1.9.2-p290:001>Date.today=>Sun,25Sep2011ruby-1.9.2-p290:002>Date.tomorrow=>Tue,27Sep2011ruby日期类是否有问题,或者这与我安装ruby​​的方式有关吗?编辑:ruby-1.9.2-p290:039>Date.current=>Mon,26Sep2011ruby-1.9.2-p290:040>DateTime.now=>Sun,25Sep201120:47:01-0500好吧,railsDate类似乎有点问题。DateTim

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-on-rails - 工厂女孩 : Automatically assigning parent objects

我刚刚进入FactoryGirl,我遇到了一个困难,我相信应该容易得多。我只是无法将文档扭曲成一个工作示例。假设我有以下模型:classLeague我想做的是:team=Factory.build(:team_with_players)并让它为我培养了一批玩家。我试过这个:Factory.define:team_with_players,:class=>:teamdo|t|t.sequence{|n|"team-#{n}"}t.players{|p|25.times{Factory.build(:player,:team=>t)}}end但这在:team=>t部分失败了,因为t并不是真

ruby-on-rails - assign 在 rspec-rails 中做什么?

我正在处理我尚未编写的代码,并试图了解RSpec的工作原理。let(:course){create:new_course}before{assign:course,course}我知道let创建了一个内存变量。在此示例中,assign做了什么? 最佳答案 您一定是在查看View规范。在rspec-railsView规范中,assign将其第二个参数分配给第一个参数命名的模板实例变量。在您的示例中,assign:course,course将模板中的@course设置为course的值。更多信息:https://www.relishap

ruby - "Assignment Branch Condition size for index is too high"是如何工作的?

Rubocop总是报告错误:app/controllers/account_controller.rb:5:3:C:AssignmentBranchConditionsizeforindexistoohigh.[30.95/24]ifparams[:role]@users=@search.result.where(:role=>params[:role])elsifparams[:q]&¶ms[:q][:s].include?('count')@users=@search.result.order(params[:q][:s])else@users=@search.result

ruby - MongoDB:无法从 BSON 类型 EOO 转换为 Date

我正在尝试使用聚合框架(使用ruby​​)并像这样投影日期:db['requests'].aggregate([{"$project"=>{_id:0,method:'$method',user:'$user',year:{'$year'=>'$timestamp'}}}])文档是这样的:{_id:ObjectId("5177d7d7df26358289da7dfd"),timestamp:ISODate("2013-04-12T03:58:05+00:00"),method:"POST",status:"200",inputsize:"874",outputsize:"4981",u

ruby-on-rails - 为什么 Date.yesterday 也算作 Date.today?

我有以下模型和方法:classUserPriceDate.today)enddefself.yesterdaywhere(:purchase_date=>Date.yesterday)end为什么在我的表单上,如果我给日期选择字段:purchase_date1/4/2012(yesterday方法)它也算作今天(today方法),如果我给它1/5/2012(今天)它是零?附言我将Rails3.0.10与PostgreSQL结合使用。更新这是我的控制台返回:$railsconsole--sLoadingdevelopmentenvironmentinsandbox(Rails3.0.10

ruby-on-rails - 使用 Date::DAYNAMES 在 Rails 中显示一周中的几天列表

我无法在表单中显示一周中的几天列表。我遇到了错误undefinedmethod`Sunday'for#但是如果我只是显示,它会给我一个列表Sunday,Monday,Tuesday,etc...toSaturday我在这里做错了什么?谢谢 最佳答案 替换与 关于ruby-on-rails-使用Date::DAYNAMES在Rails中显示一周中的几天列表,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com