看板 Ruby 關於我們 聯絡資訊
我是習慣這樣 #Controller content = Message.find(params[:id]).content #亂寫的假設你是用Message model來撈 #View <%= truncate strip_tags(content), 100 %> #當然你可以寫在Helper裡,簡化view的程式 如此一來就是既沒有html tag又是只有100個字 至於,如果中文字會被切錯? 請修改 environment.rb 在最前面加上 $KCODE = 'u' require 'jcode' -- 我愛Ruby on Rails :) http://punk.tw/ Rails, Web 2.0, Ajax, and anything. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.119.233.53 ※ 編輯: deduce 來自: 140.119.233.53 (10/05 19:59)
shelary:這個方法真的是又簡單又實用丫.. 10/06 12:19
godfat:翻了一下,rails 自己寫了個很簡單的 html parser 10/06 14:08
godfat:不過我想在一般狀況下應該夠用了,user 應該不會 10/06 14:08
godfat:瘋狂使用 nested html 才對 XD 10/06 14:08