s21gブログをRails-2.2.2に移行する作業をしてる所なのですが、
erubis-2.6.2を使っていると、テスト時に以下のようなエラーが発生しました。
pre>>
/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**
ruby>>
def _add_text_to_str(str, text)
return if !text || text.empty?
text.gsub!(/['\#\\]/, '\\\\\&')
str << text
end
<<--
となっていたので、これをひとまず以下のように直してみました(呼び出しもとをざっと見た感じだと、textを破壊的に変更しなくしても挙動に影響は無さそうだった)。
ruby>>
def _add_text_to_str(str, text)
return if !text || text.empty?
text = text.gsub(/['\#\\]/, '\\\\\&')
str << text
end
<<--
これで先ほどのエラーは出なくなったのですが、
今度は別なエラーが。
pre>>
ActionView::TemplateError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.<<
On line #13 of app/views/users/edit.html.erb
10:
11:
Account
12: <% 13: form_for(:user, @user, 14: :url => user_path(@user), :html => {:method => :put}) do |f| 15: %> 16: <%= hidden_field_tag :from, :edit %> /opt/local/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/text_helper.rb:42:in `concat' /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** ruby>> def concat(string, unused_binding = nil) if unused_binding ActiveSupport::Deprecation.warn("The binding argument of #concat is no longer needed. Please remove it from your views and helpers.", caller) end output_buffer << string end <<-- output_bufferがnilになってるって事みたいです。 Railsでerubisを使っている方、情報求む! **See Also** * [Using Erubis 2.6.2 with Rails 2.2.2 is incompatible?](http://stackoverflow.com/questions/389178/using-erubis-262-with-rails-222-is-incompatible) * [Rails 2.0.1 と 2.0.2 で ERB まわりがけっこう変更されてた](http://d.hatena.ne.jp/kwatch/20080501/1209657073)posted by
genki on Thu 25 Dec 2008 at 17:45 with 0 comments