草庐IT

time_records

全部标签

ruby-on-rails - 基于用户表单的动态 Active Record Store 访问器?

ActiveRecordStore允许您在单个单元格内序列化参数。即classUser现在所有访问器都在用户表的“选项”列中序列化。u=User.newu.option2='someoption'u.option2#=>'someoption'这对我的应用程序非常有用,因为我必须每天创建许多表单,其中90%的表单是相同的(用户名、爱好、兴趣等),然后10%是无模式的(random_option_here,another_random_option_in_another_form)。我也永远不需要按无模式选项进行排序。我所做的是为90%的始终相同的表单字段创建了1个表,然后我有另一个表包

ruby-on-rails - 在 Active Record 回调中验证日语字符

我有一个日文项目需要验证半角和全角日文字符,半角允许14个字符,全角允许7个字符。有人知道如何实现吗?现在在我的模型上classCustomervalidates_length_of:name,:maximum=>14end不是一个好的选择我目前使用的是ror2.3.5全角和半角都可以使用 最佳答案 首先,全角(全角)和半角(半角)的概念只存在于日语中的两种字符:罗马字符(即拉丁文)片假名字符韩语韩文有类似的概念,但日语平假名和汉字没有。对于片假名,半角字符有自己的Unicode代码点,并且呈现为全角字符一半的大小,尽管它们在其他方

ruby-on-rails - 即使设置了错误,Rails Record 也会被保存

这是我的凭证模型:classCredential我正在检查Controller中的证书并在Controller中设置错误,如下所示:defcreateattachment=params[:credential][:cert_file_path]cert_file_path=Rails.root.join('private','certificates',attachment.original_filename)ifattachment.present?@credential=Credential.new(credential_params)@credential.cert_file_p

Ruby,从 Date.day_fraction_to_time 获取小时、秒和时间

我找到了这个方法here.start=DateTime.nowsleep15stop=DateTime.now#minutesputs((stop-start)*24*60).to_ihours,minutes,seconds,frac=Date.day_fraction_to_time(stop-start)我有以下错误:`':privatemethod`day_fraction_to_time'calledforDate:Class(NoMethodError)我检查了/usr/lib/ruby/1.9.1/date.rb并找到了它:defday_fraction_to_time(

ruby-on-rails - Rails 国际化 : %{record} is not being translated

我的rails.pt-BR.yml上有这个:br:errors:format:!'%{attribute}%{message}'messages:restrict_dependent_destroy:one:"Nãoépossívelexcluiroregistropoisexisteum%{record}dependente"many:"Nãoépossívelexcluiroregistropoisexistem%{record}dependentes"在我的模型中,我有这个:has_many:entities,dependent::restrict_with_error每当res

ruby-on-rails - 运行 rake db :seed multiple times without creating duplicate records?

这个问题在这里已经有了答案:appendingtorakedb:seedinrailsandrunningitwithoutduplicatingdata(9个回答)关闭9年前。我想更改种子文件中的一些代码,以便在我多次运行种子命令时它不会创建重复记录。有什么方法可以从我的种子文件中修改下面的代码,这样就可以了吗?除非我弄错了,否则find_or_create_by方法在这里似乎不起作用。data_file=Rails.root.join('db/data/data.csv')CSV.foreach(data_file)do|row|TownHealthRecord.create(ci

ruby-on-rails - 为什么我不能在 Rails 中使用 Record.all.destroy?

我目前正在开始学习Ruby和RubyonRails框架。我发现在表records中,我可以找到一个id为5的记录,并使用以下代码将其删除:Record.find(5).destroy这是有道理的——我链接方法来找到记录并销毁它。但是,如果我想销毁表中的所有记录,逻辑命令如下,因为all选择器选择表中的所有记录:Record.all.destroy这会返回一个NoMethodError!我知道我可以使用Record.destroy_all或Record.delete_all来完成这个任务,但是,我想知道为什么我不能只使用most合乎逻辑的选择,而不必查找诸如delete_all之类的内容

ruby - 为什么 6.times.map 在 ruby​​ 1.8.7 而不是 1.8.6 中工作

以下代码片段在MacOSX的1.8.7中运行良好,但在Ubuntu的1.8.6中运行不佳。为什么?有解决方法吗?适用于1.8.7:$ruby--versionruby1.8.7(2009-06-08patchlevel173)[universal-darwin10.0]ltredgate15:eeglleem$irb>>6.times.map{'foo'}=>["foo","foo","foo","foo","foo","foo"]>>但在1.8.6中没有:#ruby--versionruby1.8.6(2008-08-11patchlevel287)[i686-linux]RubyE

ruby-on-rails - 如何从此 instagram json 获取 created_time?

我得到了这个json和created_time值以integer格式显示时间,而不是及时格式,但我希望这个created_time格式正确。如何以正确的格式获取created_time?"filter"=>"Normal","created_time"=>"1421677966","link"=>"http://instagram.com/p/yCfw5sKorK/","likes"=>{"count"=>1,"data"=>[{"username"=>"nikhil.thombare","profile_picture"=>"https://instagramimages-a.aka

ruby-on-rails - Ruby on Rails + Sidekiq : How do I change a scheduled job start time?

我最近开始使用Sidekiq并注意到它有一个我一直在寻找的很棒的功能:UserMailer.delay_until(5.days.from_now).find_more_friends_email基本上我可以在未来安排工作,所以我不需要我的应用程序持续轮询具有开始时间的新事件。现在这很有用,但我如何更改作业的开始时间?通常一些预定的事件会更改其开始时间。我如何在sidekiq中复制它?我知道我可以删除作业并创建一个新作业,但是否可以只修改开始时间?编辑:我建立在OtoBrglez的想法之上,这里是记录的代码:moduleTaskStuffclassTaskSetterincludeSi