8th
Fri
Ruby-1.8.7 p71にアップデート
Rubyに複数の脆弱性が発見されました。最新バージョンへのアップグレードを推奨します。
ということで、EC2で使ってるRubyをruby 1.8.7 (2008-08-08
よろしくお願いします。
Rubyに複数の脆弱性が発見されました。最新バージョンへのアップグレードを推奨します。
ということで、EC2で使ってるRubyをruby 1.8.7 (2008-08-08
よろしくお願いします。
1 class Parts < ActiveRecord::Base # STI 2 end 3 4 class Parts::Ima ge < Parts 5 end 6 7 part = Parts::Image.create! 8 p part[:type]
で何が返るのかの話。
1 part[:type] # => "Image"
1 part[:type] # => "Parts::Image"
2.1 では AR::Base.s
1 Parts::Image.store_full_sti_class # => true 2 Parts::Image.sti_name # => "Parts::Ima ge" 3 Parts::Image.create[:type] # => "Parts::Ima ge" 4 5 Parts::Image.store_full _sti_class = false 6 Parts::Image.sti_name # => "Image" 7 Parts::Image.create[:type] # => "Image"
2.1 のSTIを利用するとナベアツな世界を簡単に作成できる。
1 class Person < ActiveRecord::Base; end 2 class Nabe < Person; end 3 class Aho < Person; end 4 def Person.sti _name 5 Time.now.day % 3 == 0 ? "Aho" : "Nabe" 6 end 7 8 (1..3).map{ Nabe.create[:type] } 9 => ["Nabe", "Nabe", "Nabe"] 10 11 # Stub 12 class Time 13 def day 14 3 15 end 16 end 17 18 (1..3).map{ Nabe.create[:type] } 19 => ["Aho", "Aho", "Aho"]
Redmineで2203年の予定を立てようとしたところ、エラーが出たので原因を調べていました。
どうやら、Railsのdistance_o
でエラーが出ているようです。
1 def distance_of_time_in_ words( 2 from_time, to_time = 0, include_se conds = false) 3 from_time = from_time. to_time if 4 from_time. respond_to ?(:to_time) 5 to_time = to_time.to_time if 6 to_time.respond_to ?(:to_time) 7 distance_i n_minutes = 8 (((to_time - from_time).abs)/60).round 9 distance_i n_seconds = 10 ((to_time - from_time).abs).round
8行目あたりの減算でエラーが出ているようです。 実際、以下のような減算をしようとするとエラーが出ます。
1 Time.now - Date.parse("Mon, 01 Aug 2203").to_time 2 #=> RangeError: time - 7371010800 .000000 out of Time range
ということで、あまりにも長い時間である場合には、 以下のような例外処理で対処するようにしました。
1 module ActionView2 module Helpers 3 module DateHelper 4 def distance_o f_time_in_ words_with _limit( 5 from_time, to_time = 0, include_se conds = false 6 ) 7 distance_o f_time_in_ words_with out_limit( 8 from_time, to_time, include_se conds) 9 rescue 10 'a long time' 11 end 12 alias_meth od_chain :distance_o f_time_in_ words, :limit 13 end 14 end 15 end
これで23世紀の予定も思いのままです。