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

Comments:

or Preview
Social Bookmarks
  • Delicious
  • B_entry1157
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ