the post body contains html tags , so I cannot directly truncate it... I thought I could use sanitize to clean up the htl tags then truncate but it doesn't work ...
def write_excerpt sanitized_body = ActionController::Base.helpers.sanitize(self[:body]) self[:excerpt] = ActionController::Base.helpers.truncate(sanitized_body, :length => 300) unless sanitized_body.length < 300 end
as an example I get : "<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Nullam sit amet enim. Donec sed tellus eget sapien fringilla nonummy. Mauris a ante. Suspendisse quam sem, consequat at, commodo vit..."
there is a <p> tag ... which means that they are not stripped out ...
am I wrong ?