With rails 2.0.2 and ruby 1.8.7 you can find this error using rails truncate
helper
To solve this problem, paste this code in your enviroment.rb (eof).
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
Have a nice day!
If using Rails
< 2.2 with Ruby 1.8.7, calling
truncate
will
result in the following error:
undefined
method
`length
'
for #<Enumerable::Enumerator:0xb74f952c>
The workaround (other than upgrading to Rails
2.2 or higher), is to overwrite the truncate
method,
by inserting the following at the end of environment.rb (or where it will
be called on startup):
分享到:
相关推荐
- FIX: The TFlexPanel.FindControlAtPoint method maked virtual to realize RealTime-capability when on mouse cursor moving the flex-object search not occurs. - FIX: After deleting the selected points ...
前端开源库-node-enumerable节点可枚举,ES6就绪LINQ功能以typescript编写
Recursively Enumerable Sets and Degrees by Rovert I. Soare。递归论的书籍,Soare的,从djvu转过来的,有可能有误。经典的教材
根据AsyncEnumerator的原理改写,提供了线程函数的流程控制,线程管理,监视函数调用超时的功能。 适用于需要开启多个线程,要去线程能够长时间稳定执行某一操作的场景 不足之处欢迎留言
Enumerable是一个抽象对象(需要说明的是,javascript中并没有类的概念,所指的类也就是一个函数,继承一般指的是一个对象(父)将它的方法属性copy(通过Object.extend, copy的是引用)到子类(函数)的prototype属性(一...
这个库很大程度上受到 Ruby 的 Enumerable 模块的启发,并借用了它的大量功能。 注意:这并不意味着是一个独立的库,而是要与具有.each方法的另一种数据类型结合使用。安装作为 NPM 模块npm install enumerable-js ...
CSharp 4.0 .Net Framework V4.0 Enumerable 类
local Enumerable = require ( ' enumerable ' ) collectionInstance = Enumerable. create ({ 1 , 2 , 3 , 4 , 5 }) secondElement = collectionInstance[ 2 ] collectionInstance: each ( function ( value , ...
该项目展示了Ruby Enumerable模块中方法的重建列表。 重写的Enumerable方法是: 每个-> my_each each_with_index-> my_each_with_index 选择-> my_select 全部? -> my_all? 任何? -> my_any? 没有...
主要介绍了C#的LINQ查询中Enumerable类方法的延迟与立即执行,LINQ语言集成查询可以让C#和VB以查询数据库相同的方式操作内存数据,需要的朋友可以参考下
gem 'mongoid_enumerable' 然后执行: $ bundle 或者自己安装: $ gem install mongoid_enumerable 用法 只需在您的文档中包含MongoidEnumerable 。 添加enumerable后: 字段名称 具有可能值的数组 选项( ...
Enumerable::Statistics 提供了一些方法来计算数组和枚举中的统计汇总。 安装 将此行添加到应用程序的 Gemfile 中: gem 'enumerable-statistics' 然后执行: $ bundle 或者自己安装: $ gem install ...
概述enumerable4j是Ruby著名的移植到java 。如何使用在获取最新版本: < dependency> < groupId>io.dgroup</ groupId> < artifactId>enumerable4j</ artifactId> ${version}</ version></ dependency> 所需的Java...
在javascript中,根本找不到Enumerable的影子,因为这一块是Prototype作者从Ruby中借鉴过来的。并且Enumerable在实际中根本没有直接应用的机会,都是混入到其他的对象中,可以说是其他对象的一个“父类”(不过只是...
jar包,官方版本,自测可用
JavaScript 中的六种循环方法 Javascript中的遍历循环 对于数值索引的数组来说,可以使用标准的for循环来遍历值 ... Object.defineProperty(myobject,"a",{ //可枚举 enumerable:true, value:2, }) Object
将iterable转化为数组,如果iterable定义了toArray方法,就调用这个方法,否则利用iterable的length属性进行枚举, 如果iterable没有length属性的话就返回空数组[] Array对象除了扩展Enumerable对象的方法外,...
jar包,官方版本,自测可用
jar包,官方版本,自测可用
When dumping a non-enumerable item to a grid, nullable bools no longer cause a formatting error. When displaying XML documentation summaries in autocompletion listings and tooltips, <para> tags are no...