Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I add opensearch to a Rails app

Dan Frenette asked in General

I'm talking about the feature in chrome, it's present on GoRails, where if you type the URL of the site and hit Tab, you're able to search the site from the Chrome omnibar. I've gotten this to work with Firefox, and with just adding my site's search engine into Chrome, but for some reason I can't get the tab functionality to work.

Here's my XML file:

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
                       xmlns:moz="http://www.mozilla.org/2006/browser/search/">
  <ShortName>My Website</ShortName>
  <Description>Something Short Here</Description>
  <InputEncoding>UTF-8</InputEncoding>
  <Url type="text/html" method="get" template="<%= request.base_url %>/searches?q={searchTerms}"/>
</OpenSearchDescription>

and the link tag in my header:

%link{:href => open_searches_path, rel: "search", title: "Rails Garden", type: "application/opensearchdescription+xml"}/
Reply

That's a great question. I've never intentionally added that feature to GoRails, so I don't actually know. :-) In fact, I don't think there's any OpenSearch tags or anything so I wonder if they can detect a standard like /search url or something in my case.

Reply

I think I'd have to describe that answer as delightfully frustrating :) I'm happy Chrome threw you a bone and just tacked it on. Maybe I just need to push my site up and see what happens. Either way, thanks so much for the response!

Reply

Hahaha yeah! :P

I got a chance to read this article: https://aaronparecki.com/2011/07/11/3/how-to-let-google-power-opensearch-on-your-website

It looks like your XML file and stuff should match up with what he manually wrote out. I think you should try pushing to production and load up the XML url and make sure it renders properly with the right urls and everything and see if Google picks it up over the next few days. Pretty sure you've got it setup right.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.