2014-04-08 18 views
0

我想創建一個類的方法來轉換條款內容(description =文章內容中的100個字符),我使用LEN並且不起作用!如何計算Ruby on Rails上的文本長度?

在這裏我們去我的代碼:

class Article < ActiveRecord::Base 
    belongs_to :user, :dependent => :destroy 
    has_many :comments 
    scope :has_rating, lambda { |rating| where("rating = ?", rating) } 
    def self.has_more_than_100_char 
     where("LEN(descriptions) > 100") 
    end 
end 

在這裏我要感謝所有幫助..謝謝! :D

回答

0

解決!使用length(description)這樣的:

where("length(descriptions) > 100")