Noob question: create a link to google a parameter

Hi guys, can you spare a sec?
My question is: how can I create a link so that a customer, when
clicking an author;s name, can find the results of that name googled
already(like rails entering something in the search box, find web
results and take the user to that google page)

Pls expalin the problem, step by step, NOOB HERE :frowning:

thx a billion,
radu

radu puspana wrote:

Hi guys, can you spare a sec?
My question is: how can I create a link so that a customer, when
clicking an author;s name, can find the results of that name googled
already(like rails entering something in the search box, find web
results and take the user to that google page)

Pls expalin the problem, step by step, NOOB HERE :frowning:

Well, first, you have to find out what Google needs from you. Once
you’ve found that, it’s simply a question of building the proper URL
from Rails.

thx a billion,
radu

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

thx for your time Marnen.

I’ve written a complete custom built gui search engine in C++, and I’m
also in the process of building a new GUI search engine for ruby. In
order to understand google’s references, you have to look at their API.

http://www.googleguide.com/advanced_operators.html

This will get you started.

In terms of answering your question the search would be:

http://www.google.com/search?hl=en&as_q=&as_epq=my+author

… where search?hl=en (means english)
… where &as_q= (means start a query output)
… where &as_epq= (means find an author)
… where my+author (would be first+last name)

It seems pretty simple but it’s not. You should make sure that you
enforce URI encoding standards when submitting your URLs.

I hope this helps you to get started.

On Jan 27, 9:16 am, radu puspana [email protected] wrote:

It seems pretty simple but it’s not. You should make sure that you
enforce URI encoding standards when submitting your URLs.

What does this mean " You should make sure that you enforce URI
encoding standards when submitting your URL." ??

It basically boils down to making sure you escape special characters.
If my memory is correct ruby has some functions for url encoding
parameters in the CGI module

Fred

On Jan 26, 10:05 pm, Alpha B. [email protected] wrote:

I’ve written a complete custom built gui search engine in C++, and I’m
also in the process of building a new GUI search engine for ruby. In
order to understand google’s references, you have to look at their API.

http://www.googleguide.com/advanced_operators.html

This will get you started.

That is a great site Alpha, with the tutorial and all that, much
appreciate it.Howwver i;m in a big hurry here…

enforce URI encoding standards when submitting your URLs.
What does this mean " You should make sure that you enforce URI
encoding standards when submitting your URL." ??
Can you explain the problem in more detail or give me a link? Can I
find the answer, to the URI encoding question, in the tutorial on the
site u googleguides.com ?

I hope this helps you to get started.

Many many thx,
radu

On Jan 27, 11:16 am, radu puspana [email protected] wrote:

That is a great site Alpha, with the tutorial and all that, much
appreciate it.Howwver i;m in a big hurry here…

In terms of answering your question the search would be:

http://www.google.com/search?hl=en&as_q=&as_epq=my+author

so how can i get the parameters my and author in there.
I;m using a link_to method, something like this <%= link_to “google
it”, “http://www.google.com/search?hl=en&as_q=&as_epq=my+author” %>

any idea how to do this?

I also checked the CGI module on railsapi.com, and found something
like this

Module CGI::QueryExtension

* actionpack/lib/action_controller/cgi_ext/query_extension.rb

Methods

I

    * initialize_query

Instance Public methods
initialize_query()

Neuter CGI parameter parsing.

Source: show | on GitHub

This is it? And how do i use it?

and do you know a link on how to buid links using raisl, like the one
i need?

On Jan 27, 11:31 am, Frederick C. [email protected]

Test this out in IRB so you can see what happens:

irb
require ‘cgi’
puts CGI.escape( “J.R.R. Tolkien” )
puts CGI.escape( “Jack Daniels” )

You can create a simple helper file that does the formatting for you and
then use a simple link_tag method to submit the link to google with the
helper.

If you don’t understand what I’m saying here then you are not ready to
do this type of event in rails. You should read up on the very basics
for using rails at http://guides.rubyonrails.org/.

Take care,

JD

thx again for your time JD.
I did dry the code snippets you gave me, and i also searched the web
for the methods of CGI, and couldn’t find it anywhere, including on
railsguides.com and at railsapi.com, which served me fine up till now.

where should i get the fucntions for CGI? Can ri show them to me?How
do i do that?

if i understand correctly, regarding the link business :
first

  1. the helper file for products:(the ONLY place where I wanna use it)
    requre 'cgi
    def format_string_for_google(query)
    CGI.escape(query)
    end

2)the show.html.erb
<%=link_to “google it”, "“http://www.google.com /search?
hl=en"as_q=&“as_epq=” + format_string_for_google(@product.author)”

Is this code here of any good to my problem?

a billion thx in advance,
radu

On Jan 26, 10:05 pm, Alpha B. [email protected] wrote:

http://www.google.com/search?hl=en&as_q=&as_epq=my+author

… where search?hl=en (means english)
… where &as_q= (means start a query output)
… where &as_epq= (means find an author)
… where my+author (would be first+last name)

Just found the google api, at
http://code.google.com/apis/soapsearch/reference.html,
and there is no trace of your as_q neither as_epq :frowning: Can you tell me
why ?

It seems pretty simple but it’s not. You should make sure that you
enforce URI encoding standards when submitting your URLs.

I hope this helps you to get started.


Posted viahttp://www.ruby-forum.com/.

all my best,
radu

just tested my code in my last post and worket like a charm :slight_smile:

a zillion thx to JD >:D<

So i guess i’m kinda ready for this type of event huh? :slight_smile:

all my best,
radu

I was just providing an example of how queries are formed. Here’s a
quick and dirty test for you for the author find:

def find_author(author)
require ‘cgi’
cgi_author = CGI.escape(author)
q_author = cgi_author.gsub(/+/, ‘+author:’) + ’ ’
query = “http://www.google.com/groups?q=author:” + q_author
link_to(author, query)
end

then call that using <%= find_author(“Author Name”) %> in your views.

Note that if you searched for author in the api you’ll see that it only
uses author in google groups and the format is generally
author:first+author:middle+author:last etc… in the query output.

In your example, since all you need is an author, you just need to make
sure that the string for author is escaped correctly, not the entire
URL.

But, this should get you started.

On Jan 27, 7:46 pm, Alpha B. [email protected] wrote:

I was just providing an example of how queries are formed. Here’s a
quick and dirty test for you for the author find:

def find_author(author)
require ‘cgi’
cgi_author = CGI.escape(author)
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)

query = “http://www.google.com/groups?q=author:” + q_author
what’s with google groups? i only wanted to search websites. and while
testing it in irb, shouldn’t it be
query = “http://www.google.com/groups?q=” + q_author ??

link_to(author, query)
end

then call that using <%= find_author(“Author Name”) %> in your views.

Note that if you searched for author in the api you’ll see that it only
uses author in google groups and the format is generally
author:first+author:middle+author:last etc… in the query output.

In your example, since all you need is an author, you just need to make
sure that the string for author is escaped correctly, not the entire
URL.

But, this should get you started.

much appreciate it!!
radu

On Jan 27, 7:46 pm, Alpha B. [email protected] wrote:

I was just providing an example of how queries are formed. Here’s a
quick and dirty test for you for the author find:

def find_author(author)
require ‘cgi’
cgi_author = CGI.escape(author)
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)

query = “http://www.google.com/groups?q=author:” + q_author
what’s with google groups? i only wanted to search websites. and while
testing it in irb, shouldn’t it be
query = “http://www.google.com/groups?q=” + q_author ??

link_to(author, query)
end

then call that using <%= find_author(“Author Name”) %> in your views.

Note that if you searched for author in the api you’ll see that it only
uses author in google groups and the format is generally
author:first+author:middle+author:last etc… in the query output.

In your example, since all you need is an author, you just need to make
sure that the string for author is escaped correctly, not the entire
URL.

But, this should get you started.

much appreciate it!!
radu

� 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…

i don’t know where to begin in thanking you for all the time and skill
that you put into my problem, and for explaining the problem step by
step, just like someone should for a noob.
I;ll keep in mind every tip u gave me and try tsome day to undestand
the thing with the classes and the helpers for queries and become a
query search googel exper.
Until then there is a lot of work for me, but i know i can rely on my
friends here, on RoR Talk.

all my best,
radu

p.s i know a lot of programmers and us noob programmers love a gooed
rock song, so care for Mark Knopfler? :slight_smile:
i know i do
so this is a small gift for helping a fellowpRoR programmer still in
noob form :slight_smile:

http://www.youtube.com/watch?v=F1-uOIKJLvg

Alpha B. wrote:

No problem Radu, glad to help. Definitely start with the basics and work
your way up. One thing I would definitely suggest is learning how to
create
tests for your code and to also read a few books. I own a Kindle so I
have
a small library of roughly 12 rails books and 4 ruby books.

And for those with iPhones, you can now do likewise with the Kindle app.

If you
don’t
like Kindle, you can go to http://my.safaribooksonline.com/ which is
another
fantastic site that has a small monthly subscription - around 9 dollars
or
so a month. What I like about safaribooksonline is that you can select
and
rotate up to 4 books a month. So, I keep 4 books for one month, read
through them and then the following month I swap them out for new books.

Personally, I don’t like the idea of learning Rails from books. It
changes too fast. (I’m also a cheapskate… :slight_smile: )

If
one is really good for reference, I add it to my Kindle.

Books = food

Yeah.

Sincerely,

Joel D.
Website Bio: http://jdezenzio.com/
Rails Production Sites: http://ncaastatpages.com

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

No problem Radu, glad to help. Definitely start with the basics and work
your way up. One thing I would definitely suggest is learning how to
create
tests for your code and to also read a few books. I own a Kindle so I
have
a small library of roughly 12 rails books and 4 ruby books. If you
don’t
like Kindle, you can go to http://my.safaribooksonline.com/ which is
another
fantastic site that has a small monthly subscription - around 9 dollars
or
so a month. What I like about safaribooksonline is that you can select
and
rotate up to 4 books a month. So, I keep 4 books for one month, read
through them and then the following month I swap them out for new books.
If
one is really good for reference, I add it to my Kindle.

Books = food

Sincerely,

Joel D.
Website Bio: http://jdezenzio.com/
Rails Production Sites: http://ncaastatpages.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs