=1B$BB<ED$G$9!#=1B(B

On 2010/04/30, at 18:20, NARUSE, Yui wrote:

>> =
=1B$B:#;~$N%G!<%?%Y!<%9%7%9%F%`$O%3%M%/%7%g%s$d%F!<%V%k$d%+%i%`$,%(%s%3!<%=
G%#%s%0$r;}$C$F$k$N$G!"=1B(B
>> =
=1B$B$=3D$N%(%s%3!<%G%#%s%0$r%I%i%$%PB&$GI3$E$1$F$d$k$N$,0lHV>pJs$,Mn$A$J$=
/$FNI$$$H;W$$$^$9!#=1B(B
>> =
=1B$B$=3D$l$G=1B(BPostgreSQL=1B$B$N%"%@%W%?$K$O$=3D$&$$$&%Q%C%A$rAw$C$F=1B=
(Baccept=1B$B$5$l$^$7$?!#=1B(B
>=20
> SQLite3 =1B$B$N%I%i%$%P$G$"$k!"=1B(Bsqlite3-ruby =
=1B$B$b<!$N%P!<%8%g%s$G%(%s%3!<%G%#%s%0$r=1B(B
> =1B$B@_Dj$9$k$h$&$K$J$j$^$9!#=1B(B (thanks Aaron)

=1B$B$3$NBP1~$OHs>o$K4r$7$$$G$9!#=1B(B

> Rails =1B$B$N%G%U%)%k%H$G$"$k=1B(B SQLite3 =
=1B$B$,HsBP1~$@$C$?$N$GF'$`?M$,B?$+$C$?$N$@$H;W$$$^$9$,!"=1B(B
> =1B$B$3$l$G:#8e$O8:$C$F$$$/$s$8$c$J$$$G$7$g$&$+!#=1B(B

=1B$B;d$O8=3D>u$G$O!"0J2<$N$h$&$J5!G=3D$r=1B(B ActiveRecord =
=1B$B$XCmF~$9$k$3$H$GBP=3Dh$7$F$$$^$9!#=1B(B

http://gist.github.com/381834

if defined?(ActiveRecord)
  class ActiveRecord::Base
    def read_attribute_with_enforcing_utf8(attr_name)
      v =3D read_attribute_without_enforcing_utf8(attr_name)
      if String =3D=3D=3D v && column_for_attribute(attr_name).text?
        return v.force_encoding(Encoding::UTF_8) if v.encoding =3D=3D =
Encoding::ASCII_8BIT
      end
      return v
    end
    alias_method_chain :read_attribute, :enforcing_utf8

    class << self
      private
      def define_read_method_with_enforcing_utf8(symbol, attr_name, =
column)
        define_read_method_without_enforcing_utf8(symbol, attr_name, =
column)
        if column.text?
          self.class_eval <<-END_DEFINITION, __FILE__, __LINE__
            def #{symbol}_with_enforcing_utf8
              v =3D #{symbol}_without_enforcing_utf8
              v =3D v.force_encoding(Encoding::UTF_8) if v && v.encoding =
=3D=3D Encoding::ASCII_8BIT
              return v
            end
            alias_method_chain :#{symbol}, :enforcing_utf8
          END_DEFINITION
        end
      end
      alias_method_chain :define_read_method, :enforcing_utf8
    end
  end
end

--
Kenta Murata
OpenPGP FP =3D FA26 35D7 4F98 3498 0810 E0D5 F213 966F E9EB 0BCC

=1B$BK\$r=3Dq$-$^$7$?=1B(B!!
=1B$B!X=1B(BRuby =1B$B5U0z$-%l%7%T!Y=1B(B =
http://www.amazon.co.jp/dp/4798119881/mrkn-22

E-mail: mrkn / mrkn.jp
twitter: http://twitter.com/mrkn/
blog: http://d.hatena.ne.jp/mrkn/