`
jsntghf
  • 浏览: 2476647 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

undefined method `length' for Enumerable

阅读更多

如果你的环境是ruby1.8.7、rails2.0.2,你使用truncate时,可能会遇到undefined method `length' for Enumerable的错误。

 

为了解决这个问题,你可以将以下代码写在任意一个启动服务时可以加载的文件中。

 

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的版本升级到2.2.X也行。

分享到:
评论

相关推荐

    前端开源库-node-enumerable

    前端开源库-node-enumerable节点可枚举,ES6就绪LINQ功能以typescript编写

    Recursively Enumerable Sets and Degrees(Soare)

    Recursively Enumerable Sets and Degrees by Rovert I. Soare。递归论的书籍,Soare的,从djvu转过来的,有可能有误。经典的教材

    通过Enumerable实现线程控制(源码 更新)

    根据AsyncEnumerator的原理改写,提供了线程函数的流程控制,线程管理,监视函数调用超时的功能。 适用于需要开启多个线程,要去线程能够长时间稳定执行某一操作的场景 不足之处欢迎留言

    Prototype使用指南之enumerable.js

    Enumerable是一个抽象对象(需要说明的是,javascript中并没有类的概念,所指的类也就是一个函数,继承一般指的是一个对象(父)将它的方法属性copy(通过Object.extend, copy的是引用)到子类(函数)的prototype属性(一...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    - ADD: Added the method TEnumProp.SetItem for convenience. The enumerable type can now be defined as a sequence: TEnum = ( eOne, eTwo ); . . . EnumProp.SetItem(integer(eOne), 'One'); EnumProp....

    Enumerable.js:适用于所有类型集合的实用函数

    这个库很大程度上受到 Ruby 的 Enumerable 模块的启发,并借用了它的大量功能。 注意:这并不意味着是一个独立的库,而是要与具有.each方法的另一种数据类型结合使用。安装作为 NPM 模块npm install enumerable-js ...

    CSharp 4.0 .Net Framework V4.0 Enumerable 类

    CSharp 4.0 .Net Framework V4.0 Enumerable 类

    enumerable.lua:一个lua集合库

    local Enumerable = require ( ' enumerable ' ) collectionInstance = Enumerable. create ({ 1 , 2 , 3 , 4 , 5 }) secondElement = collectionInstance[ 2 ] collectionInstance: each ( function ( value , ...

    enumerable-methods

    该项目展示了Ruby Enumerable模块中方法的重建列表。 重写的Enumerable方法是: 每个-> my_each each_with_index->​​ my_each_with_index 选择-> my_select 全部? -> my_all? 任何? -> my_any? 没有...

    C#使用LINQ中Enumerable类方法的延迟与立即执行的控制

    主要介绍了C#的LINQ查询中Enumerable类方法的延迟与立即执行,LINQ语言集成查询可以让C#和VB以查询数据库相同的方式操作内存数据,需要的朋友可以参考下

    mongoid_enumerable:Mongoid 可枚举

    gem 'mongoid_enumerable' 然后执行: $ bundle 或者自己安装: $ gem install mongoid_enumerable 用法 只需在您的文档中包含MongoidEnumerable 。 添加enumerable后: 字段名称 具有可能值的数组 选项( ...

    enumerable-statistics

    Enumerable::Statistics 提供了一些方法来计算数组和枚举中的统计汇总。 安装 将此行添加到应用程序的 Gemfile 中: gem 'enumerable-statistics' 然后执行: $ bundle 或者自己安装: $ gem install ...

    enumerable4j:Ruby的惊人“ Enumerable”移植到Java

    概述enumerable4j是Ruby著名的移植到java 。如何使用在获取最新版本: < dependency> < groupId>io.dgroup</ groupId> < artifactId>enumerable4j</ artifactId> ${version}</ version></ dependency> 所需的Java...

    Prototype源码浅析 Enumerable部分之each方法

    在javascript中,根本找不到Enumerable的影子,因为这一块是Prototype作者从Ruby中借鉴过来的。并且Enumerable在实际中根本没有直接应用的机会,都是混入到其他的对象...不过多数是应用在数组上,比如原生数组的forEac

    enumerable-java-0.4.0.jar

    jar包,官方版本,自测可用

    【JavaScript源代码】JavaScript 中的六种循环方法.docx

    JavaScript 中的六种循环方法  Javascript中的遍历循环  对于数值索引的数组来说,可以使用标准的for循环来遍历值 ... Object.defineProperty(myobject,"a",{ //可枚举 enumerable:true, value:2, }) Object

    Prototype使用指南之array.js

     将iterable转化为数组,如果iterable定义了toArray方法,就调用这个方法,否则利用iterable的length属性进行枚举, 如果iterable没有length属性的话就返回空数组[] Array对象除了扩展Enumerable对象的方法外,...

    HTML5-Canvas五彩纸屑飘落动画特效.zip

    descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor...

    enumerable-java-weaver-0.4.0.jar

    jar包,官方版本,自测可用

    enumerable-java-0.4.0-sources.jar

    jar包,官方版本,自测可用

Global site tag (gtag.js) - Google Analytics