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
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
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.
Google Search Operators - Google Guide
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:
"my author" - Google Search
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ā, ā"my author" - Google Searchā %>
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
- 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:
"my author" - Google Search
ā¦ 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
Google for Developers - Software Development Guides, Tools & More,
and there is no trace of your as_q neither as_epq 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
a zillion thx to JD >:D<
So i guess iām kinda ready for this type of event huh?
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?
i know i do
so this is a small gift for helping a fellowpRoR programmer still in
noob form
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ā¦ )
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