Kashiftufail
Kashiftufail

Reputation: 10885

Rails Truncate and raw not working together

I'm using Rails 4 and come across with very strange problem. That raw and truncate not working properly together.

     <%= raw(job.description)%>  # working properly

     <%= raw(truncate(job.description,:length => 200))%>  # Not strip html tags

     <%= truncate((raw job.description),:length => 200)%>  # Not strip html tags

What the problem is?

Any help please??

Upvotes: 5

Views: 3394

Answers (2)

Deepak Mahakale
Deepak Mahakale

Reputation: 23661

You can make use of truncate with sanitize

truncate(sanitize(job.description, tags: []), length: 200)

Upvotes: 2

Oz Ben-David
Oz Ben-David

Reputation: 1657

I'm not sure what you are trying to accomplish so simply try

raw job.description.truncate(200)

and\or

(raw job.description).truncate(200)

Upvotes: 20

Related Questions