s21gブログをRails-2.2.2に移行する作業をしてる所なのですが、 erubis-2.6.2を使っていると、テスト時に以下のようなエラーが発生しました。

   1  /opt/local/lib/ruby/gems/1.8/gems/erubis-2.6.2/lib/erubis/enhancer.rb:666:in `gsub!': can't modify frozen string (TypeError)

erubisのソースを見てみると、

lib/erubis/enhancer.rbL666

   1      def _add_text_to_str(str, text)
   2        return if !text || text.empty?
   3        text.gsub!(/['\#\\]/, '\\\\\&')
   4        str << text
   5      end

となっていたので、これをひとまず以下のように直してみました(呼び出しもとをざっと見た感じだと、textを破壊的に変更しなくしても挙動に影響は無さそうだった)。

   1      def _add_text_to_str(str, text)
   2        return if !text || text.empty?
   3        text = text.gsub(/['\#\\]/, '\\\\\&')
   4        str << text
   5      end

これで先ほどのエラーは出なくなったのですが、 今度は別なエラーが。

   1  ActionView::TemplateError: You have a nil object when you didn't expect it!
   2  You might have expected an instance of Array.
   3  The error occurred while evaluating nil.<<
   4      On line #13 of app/views/users/edit.html.erb
   5  
   6      10:   <div id="user-parameters">
   7      11:     <h2>Account</h2>
   8      12:     <%
   9      13:     form_for(:user, @user,
  10      14:       :url => user_path(@user), :html => {:method => :put}) do |f|
  11      15:     %>
  12      16:     <%= hidden_field_tag :from, :edit %>
  13  
  14      /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/text_helper.rb:42:in `concat'
  15      /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/form_helper.rb:252:in `form_for'

form_forの中のconcatでエラーが出ている模様。こちらもソースを見てみると、

actionpack-2.2.2/lib/action_view/helpers/text_helper.rb

   1        def concat(string, unused_binding = nil)
   2          if unused_binding
   3            ActiveSupport::Deprecation.warn("The binding argument of #concat is no
   4   longer needed.  Please remove it from your views and helpers.", caller)
   5          end
   6          output_buffer << string
   7        end

output_bufferがnilになってるって事みたいです。

Railsでerubisを使っている方、情報求む!

See Also

posted by Png genki on Thu 25 Dec 2008 at 17:52

しばらくRails-2.0.2で運用しておりましたが、このたびRails-2.2.2対応にアップデートしました。

いくつか引っかかった所などをメモしておきます。

  • background_fuに手を入れたものを使っていたのですが、2.2.2で動かなかったので、最新のコードをgithubからpullしてmerge.
  • それでもsend!を呼び出してる所があって、エラーが出ていたので、sendを使うように書き換えた。
  • プラグイン版のjpmobileが残っていてエラーを出していたので、一旦外す。
  • erubisが以下のようなエラーを出すようになった。
       1  /opt/local/lib/ruby/gems/1.8/gems/erubis-2.6.2/lib/erubis/enhancer.rb:666:in `gsub!': can't modify frozen string (TypeError)
    
  • TemplateHandler::Baseにcompileメソッドが必要になっていた
  • Rails-2.2.x対応版のprawntoを入れる。

ここまででテスト落ちずに全部実行できるようになった。

  • config/routes.rbの解釈が微妙に変わったせいでテストが通らなくなった所を、通るように修正。

だいたい以上で移行完了。

posted by Png genki on Thu 25 Dec 2008 at 14:00
Contents
erubis-2.6.2がRails-2.2.2だと動かないかも?
s21gブログをRails-2.2.2対応にアップデートしました
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
瀧内元気: おお、チェックしてみます。thx! '11-12
overisland: Reeder for iPhone もこの UI を実装していますね。 '11-12
瀧内元気: その情報は見たのですが、以下のサイトによると、現在はまた必要になってるっぽいんですよね。 ... '11-12
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ