shitou's blog 
Home About Feed | MIX BOY 塌客

Tags "bug"

14
Jan

rails undefined method 'length' by shitou

0

今天在使用rails的helper方法truncate截取字符串时遇到一个问题,在开发环境下(windows平台)运行都是正常的,但一放到production环境(debian)后就抛出异常:

 

undefined method 'length' for #<Enumerable::Enumerator:0x243a7a4>

 

错误的地方就是truncate方法, 后来google才发现原来是ruby1.8.7与rails2.0.2的一个bug, 好像现在的rails2.1.0同样也有这个问题, 但之前我在RHEL平台上部署时用的同样的版本就没出现过这个问题。。, 难道只有在debian上才有, 还好找到了修复方法, 在environment.rb加入:

 

module ActionView
  module Helpers
    module TextHelper
      def truncate(text, length = 30, truncate_string = "...")
        if text.nil? then return end
        l = length - truncate_string.chars.to_a.size
        (text.chars.to_a.size > length ? text.chars.to_a[0...l].join + truncate_string : text).to_s
      end
    end
  end
end

 

就是重写rails的truncate方法, 这样就行了,当然也可以对ruby进行降级, 采用1.8.6, 不过还是这个方法简单点.

Tags: bug

2009-01-14 10:44:27, 469 reviews

send to mailbox

Your email:

Tags

U-ka saegusa IN db command Mai Kuraki Norah Jones log iPhoneException ACG Mac Safari objective-c CouchDB LVS AJAX debian 推荐 AMQP google mail bug gettext Erlang 北京 iptables 架构 tips mysql backup function 我看 postfix 监控 SEO cache Etag memcache thread 进程 线程 无锡 yield file column mixboy xml rss gems ruby shitou shell lighttpd 安全 csrf 公司 nginx linux 模块 apache webserver 朋友 大学 生活 尼古拉斯凯奇 movie 文件同步 笑笑 歌词 auto complete plugin rails music ubuntu blog

Category

  • iPhone[17]
  • Erlang[4]
  • google[8]
  • 生活[38]
  • 音乐[11]
  • 电影[11]
  • linux[20]
  • web server[6]
  • mail server[3]
  • cluster[1]
  • system manage[5]
  • ruby[18]
  • ruby on rails[27]
  • 开源[3]

Episode

  • iPhoneException
  • shell
  • thread
  • memcache

Recent Comments

  • now I see it.. kat's stories forced to str...
  • "One had to cram all this stuff into one's...
  • Robert schumann, and johannes brahms always ins...
  • по моему мнению: спасибо.. знакомства для ...
  • 已经有CouchDB的Ruby接口了, 看这里 http://github.com/lang...
  • 期待你的资料啊 大哥你得快点来啊
  • oreilly出书了,在线阅读 http://books.couchdb.org/relax/
  • 穿越来同草!
  • 一直以来,对待工作,你的责任心很强;对待生活,你的要求却很简单;对待自己,你的关注却不够啊。晚...
  • 过两天温度就应该又上去了

Popular Posts

  • MySQL Innodb备份
  • 准备开始学习Erlang了(恶狼, 二郎..)
  • Lighttpd配置参数
  • iPhone上的HelloWorld终于跑起来了
  • Etag和Expire

Recommended Posts

  • Mai Kuraki -永远より ながく
  • U-ka saegusa IN db Final Best
  • Heaven Can Wait - Charlotte Gainsbou
  • Ruby遍历MemCached的key
  • Norah Jones - The fall
  • 请记得仰望梦想的姿势
  • Shell: 统计MySQL InnoDB表的大小
  • Rails Benchmark
  • 发送异常到邮箱
  • I Miss Nobody
  • Music4u, Vol. 1
  • my macbook
  • Mai Kuraki-Beautiful
  • 10首最伤情英文歌曲精选
  • Mai Kuraki - PUZZLE/Revive

Friends' blogs

  • levy
  • sphance
  • andreas

Login

   注册

留言 查看留言

留言

   取消

留言 查看留言


Statistics

  • 访问次数: 55356
  • 今天访问: 797
  • 日志: 172
  • 评论: 108
  • 音乐: 9
  • 用户: 158


 

just DO NOT support IE

close