>> � q_author = cgi_author.gsub(/\+/, '+author:') + ' '
> what does this line do? I know gsub will replace the +author text with
> something that comes out from /\+/ (althought i don't know what this
> regwxp could generate)

gsub is used for substitution.  Unlike sub which only substitutes the 
first regexp match found, gsub substitutes any number of matches found.

The /\+/ is looking for anything that has a + symbol.  So, My+Name+Is 
etc.  When you use the cgi method above on the author name, it will 
correctly escape the html, which is necessary because an author's name 
could be anything from First Middle Last to First M. Last etc.

Once the cgi method correctly formats the author's name, you are just 
providing a bit of substitution for Google's query engine.  It's going 
to replace the + between the author's name with '+author:' and then add 
a space after the entire string so that if you had a name like John+Doe, 
it would appear as:

John+author:Doe

The query then appends this string:

query = "http://www.google.com/groups?q=author:"; + q_author

.. to this ..

to form..

http://www.google.com/groups?q=author:John+author:Doe

And if you click the link for this above, you'll see what happens when 
you get to google.

Like I mentioned, you can tidy it up a bit if you want or keep it as 
needed.  It will work.  Just replace any author's name in your view with 
the helper method like I showed above and then test out your view by 
clicking on the author links and you'll see what happens.

You can add a lot more to this helper method or build yourself an entire 
class for handling google queries and use methods from the class in your 
helpers, which is what I do.  I thought about handing out a plugin that 
does all of this, but because google changes things often, I don't want 
to have to manage a project at this time.  Maybe in the future 
sometime..




-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "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.

Reply via email to