修复当课程描述中有特殊标签是,课程列表描述显示有误的BUG

This commit is contained in:
sw 2014-07-10 16:48:13 +08:00
parent 39434766e3
commit 47ad20421e
1 changed files with 12 additions and 1 deletions

View File

@ -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 =~ /^<!/)
end
return output
end
def extra_frozen?
errors[:extra].blank? && !(new_record? || extra.blank?)
end