kshama
kshama

Reputation: 1627

Need help in highlighting the text in rails

I have built a free text search engine in rails ,I want to highlight search word in result page where, each word in the phrase may not be adjacent to each other( that is they may be present in any part of the text content). I have tried with highlight method of ActionView::Helpers::TextHelper as

<%= highlight(content.body, @search_keywords) -%>

(Where @search_keywords has the phrase)

But this is not high lighting a phrase. Can any one help me in this.

Thanks in advance.

Upvotes: 1

Views: 1440

Answers (1)

Tatjana N.
Tatjana N.

Reputation: 6225

You can pass array of words to highlight function. See here.

<%= highlight(content.body, @search_keywords.split) -%>

Upvotes: 6

Related Questions