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)
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
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.
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.
.. 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'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.
.. 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.
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 ?
> 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
> 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.
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/.
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
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.
.. 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)
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.
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)
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.
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)
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.
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:
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?
i know i do
so this is a small gift for helping a fellowpRoR programmer still in
noob form
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.
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.. )
If
one is really good for reference, I add it to my Kindle.