开发者

Difference Between Rails 2.2 and 2.3.5? ActionMailer.Utils

I would think this is a Ruby difference, but I'm using the same Ruby version 1.8.7. This is related to this post (开发者_如何学Goto answer "why do you need this?"). This code works in 2.2.2

Loading development environment (Rails 2.2.2)
>> module ActionMailer
>> Utils.normalize_new_lines("blah")
>> end

but in 2.3.5 it fails

Loading development environment (Rails 2.3.5)
>> module ActionMailer
>> Utils.normalize_new_lines("blah")
>> end
NoMethodError: undefined method `normalize_new_lines' for ActionMailer::Utils:Module
from (irb):2

What's new about 2.3.5 that this would fail? The method is there in 2.3.5, so this works

Loading development environment (Rails 2.3.5)
>> include ActionMailer
>> include Utils
>> normalize_new_lines("blah")

I realize this is probably an important Rails difference.


Looks like the code changed from version 2.2 to version 2.3.5

old:

module ActionMailer
  module Utils #:nodoc:
    def normalize_new_lines(text)
      text.to_s.gsub(/\r\n?/, "\n")
    end
    module_function :normalize_new_lines
  end
end

new:

module ActionMailer
  module Utils #:nodoc:
    def normalize_new_lines(text)
      text.to_s.gsub(/\r\n?/, "\n")
    end
  end
end

I guess you could restore the old behavior by calling module_function yourself:

$ script/console
Loading development environment (Rails 2.3.5)
>> module ActionMailer
>> module Utils
>> module_function :normalize_new_lines
>> end
>> Utils.normalize_new_lines("blah")
>> end
=> "blah"
>> 

EDIT: Or better yet just include the module (per Simone)

>> include ActionMailer::Utils

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜