Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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??

like image 847
Kashiftufail Avatar asked Jul 04 '13 17:07

Kashiftufail


2 Answers

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)
like image 68
obenda Avatar answered Oct 01 '22 07:10

obenda


You can make use of truncate with sanitize

truncate(sanitize(job.description, tags: []), length: 200)
like image 42
Deepak Mahakale Avatar answered Oct 01 '22 07:10

Deepak Mahakale