Glossary module

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.

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.

create a helper that would parse the content of the page and would auto link

if a certain term corresponds to a glossary record.

if the pages are gonna be hit quite a lot, i suggest caching the list of words so

you minimize the number of hits to the db.

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:

  1. Send the names of all the Glossary as json object when you load the page, bcoz you will be matching the contents of pages with names, i guess.
  2. You could send the names as a string like " name1 | name2 | name3 | …| " or simply pass a hash.
  3. 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 coming from server. How you want to do the matching would determine, in which format you are sending the names json from server.

Advantages of this approach:

  1. 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 matches for each page’s contents. You would have understood what I mean to convey here.
  2. Use javascript libraries when it comes to things like these, until and 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.

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.

Why are you using the server to do this, when you could use client processor to do the matching for you. NOTE: He just wants to highlight them and not show them as links.

If it had been links, I would have completely agreed with your approach.

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.

Why are you using the server to do this, when you could use client processor to do the matching for you. NOTE: He just wants to highlight them and not show them as links.

If it had been links, I would have completely agreed with your approach.

I’m assuming that he wants to link them because I think there’s no use just highlighting them.

Jim ruther Nill wrote in post #984685:

Jim ruther Nill wrote in post #984685:

I’m assuming that he wants to link them because I think there’s no use

just

highlighting them.

Ideally, I’d display the definition of the matched term in the Page

itself but a glossary listing will also be available.

Honestly, I’m not really sure what the best method of displaying the

definition on the page would be; I don’t want the definition to be

obtrusive.

Where do you want to show the definition, and on what event, i mean is it like when you hover over the highlighted text or what?

Jatin Kumar wrote in post #984692:

Jatin Kumar wrote in post #984692:

itself but a glossary listing will also be available.

Honestly, I’m not really sure what the best method of displaying the

definition on the page would be; I don’t want the definition to be

obtrusive.

Where do you want to show the definition, and on what event, i mean is it

like when you hover over the highlighted text or what?

onmouseover

if this is the functionality you want, then i agree that you can just create a js function

that would bind an onmouseover event to specific words of the content.

Jatin Kumar wrote in post #984692:

itself but a glossary listing will also be available.

Honestly, I’m not really sure what the best method of displaying the

definition on the page would be; I don’t want the definition to be

obtrusive.

Where do you want to show the definition, and on what event, i mean is it

like when you hover over the highlighted text or what?

onmouseover

When you are doing the matching using jQuery, you could change the content of pages, in such a way that each matching word (highlighted word) is like an anchor tag or simple text, which when hovered over, can do two things via jQuery:

  1. Fire an ajax call to the server, asking for the description of the name. or

    1. Send the description alongwith the names in json format, and when hovered over, display the description from the json object you have.

Jatin Kumar wrote in post #984692:

itself but a glossary listing will also be available.

Honestly, I’m not really sure what the best method of displaying the

definition on the page would be; I don’t want the definition to be

obtrusive.

Where do you want to show the definition, and on what event, i mean is it

like when you hover over the highlighted text or what?

onmouseover

When you are doing the matching using jQuery, you could change the content of pages, in such a way that each matching word (highlighted word) is like an anchor tag or simple text, which when hovered over, can do two things via jQuery:

  1. Fire an ajax call to the server, asking for the description of the name.

I think this is the better option. plus you can minimize the request to the server if you somehow store already hovered words into a global js variable.

so onmouseover, check the array if the word is there. if it’s there, then you don’t need to do an ajax request anymore.

I remember there is a gem acts_as_tags, Is it useful for you?