On Tue, Mar 1, 2011 at 10:13 AM, Pale H. [email protected]
The application I’m currently working on has a Glossary model. The
Glossary table has columns for the term and its definition.
The application also has Pages which have content. The content needs to
highlight any words that match a term in the Glossary table.
There’ll be a few ways to do this but I’d appreciate your advice on the
way you’d accomplish this.
Yes, there are a lot of ways to do this. My approach would be:
- Send the names of all the Glossary as json object when you load
page, bcoz you will be matching the contents of pages with names, i
- You could send the names as a string like " name1 | name2 | name3
…| " or simply pass a hash.
- Now, when you display the contents of a page, use jQuery to do the
matching on the names json with the contents in the http_response
How you want to do the matching would determine, in which format you are
sending the names json from server.
Advantages of this approach:
- You are not saving the matches in DB, although you can. But if you
change your glossary, you would have to do it again and change the
for each page’s contents. You would have understood what I mean to
unless you want to save the changes(matches here) in DB.
There could be a better way of doing this, so lets wait and see what the
experienced ones here say about it.