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.

On Tue, Mar 1, 2011 at 6:13 PM, Pale H. [email protected] wrote:

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.

http://groups.google.com/group/rubyonrails-talk?hl=en.

On Tue, Mar 1, 2011 at 10:13 AM, Pale H. [email protected]
wrote:

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.

On Tue, Mar 1, 2011 at 10:52 AM, Jim Ruther N. [email protected]
wrote:

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.

There’ll be a few ways to do this but I’d appreciate your advice on the

Jim ruther Nill wrote in post #984685:

On Tue, Mar 1, 2011 at 6:56 PM, Jatin kumar
[email protected]wrote:

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.

On Tue, Mar 1, 2011 at 6:56 PM, Jatin kumar
[email protected]wrote:

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

you minimize the number of hits to the db.

To post to this group, send email to [email protected].
visit my blog at http://jimlabs.heroku.com


You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.

On Tue, Mar 1, 2011 at 11:11 AM, Pale H. [email protected]
wrote:

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?

On Tue, Mar 1, 2011 at 7:37 PM, Pale H. [email protected] wrote:

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.

http://groups.google.com/group/rubyonrails-talk?hl=en.

On Tue, Mar 1, 2011 at 11:37 AM, Pale H. [email protected]
wrote:

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

  2.  Send the description alongwith the names in json format, and 

when
hovered over, display the description from the json object you have.

Jatin K. wrote in post #984692:

On Tue, Mar 1, 2011 at 11:11 AM, Pale H. [email protected]
wrote:

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

On Tue, Mar 1, 2011 at 7:57 PM, Jatin kumar
[email protected]wrote:

Honestly, I’m not really sure what the best method of displaying the
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.

“Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.

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