-
後部文字列を取り出すtruncateを書く 2008-03-15 16:48:19
milookのリニューアル作業をしていて、文字列の後部を取り出す必要が出てきたのですが、truncateは前部しか取り出せません。なので、自分で作りました。
config/environment.rbmodule ActionView module Helpers module TextHelper def truncate_with_back(text, length = 30, truncate_string = "...") if length >= 0 truncate_without_back(text, length, truncate_string) else return if text.blank? text.chars.length > -length ? "#{truncate_string}#{text.chars[length..-1]}" : text end end alias_method_chain :truncate, :back end end end

コメント(
リンク元(48)