From 47ad20421e3fbe9c481e1fc9290863e230550c0d Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Thu, 10 Jul 2014 16:48:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BD=93=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0=E4=B8=AD=E6=9C=89=E7=89=B9=E6=AE=8A=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E6=98=AF=EF=BC=8C=E8=AF=BE=E7=A8=8B=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0=E6=98=BE=E7=A4=BA=E6=9C=89=E8=AF=AF=E7=9A=84?= =?UTF-8?q?BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/models/course.rb b/app/models/course.rb index bac28e4c2..7db789a7a 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -92,10 +92,21 @@ class Course < ActiveRecord::Base # 课程的短描述信息 def short_description(length = 255) - description.gsub(/<\/?.*?>/,"").strip if description + description.gsub(/<\/?.*?>/,"").html_safe if description #description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description end + def strip_html(html) + return html if html.empty? || !html.include?('<') + output = "" + tokenizer = HTML::Tokenizer.new(html) + while token = tokenizer.next + node = HTML::Node.parse(nil, 0, 0, token, false) + output += token unless (node.kind_of? HTML::Tag) or (token =~ /^