Ruby on Rails i18n problem - ruby-on-rails

I have a site created by Ruby on Rails. Before I implement HTTP_ACCEPT_LANGUAGE to detect the client's computer language and set the site's language with i18n, the site can be found on Google.
After I use HTTP_ACCEPT_LANGUAGE and i18n, Google stop crawling my site. And worst, some countries receives Read Time Out Error when going to my site.
What is the problem? (using GeoIP is not preferably, detecting the client's computer language is more meaningful)

Apparently HTTP_ACCEPT_LANGUAGE is not available to Google bot. See this article for reference.

As #picardo has said, Google bot crawles the web without sending the HTTP_ACCEPT_LANGUAGE header. I've implemented a Rails gem to automatically set the I18n.locale based on this header, but then fall back to guessing based on the domain name suffix, so that it still detects correct language for Google bot. The gem is called locale_detector.

Related

Using routing with faye::WebSocket in ruby

I am experimenting with websockets in my ruby on Rails server. I am trying faye-websocket as described in here.
Initial tests look promising (I am using a python client and I am able to connect to the websocket) but I have a newbie question that keeps bugging me. Including my websockets library as a middleware in ruby seems to capture ALL requests from my client that are websocket connections. In such case, how do I differentiate (and reply differently) to client calls with different routing (e.g. calls to http://myserver.com/apple and http://myserver.com/pear being both websockets)?
EDIT
I found that the env variable contains the field "REQUEST_PATH" which has the information of the routing requested by the client. I can use that variable to return the appropriate answer to each one of the different client calls. Is there any more "elegant" way to do it?

Using an API key in Rails App

I just got an API key for a database I wish to access and want to start building my Rails app. However I dont know where to begin with the API key. Specifically I want to use the brewerydb data and I am building an app where users can find the closest brewery to their location. Can anyone tell me how to get started? I am new to Rails and have never used an API before. I don't know where to begin. What file should I put it in, etc... I know I should probably update the GEMFILE, where else?
Thanks!
Check the documentation for the API. That's all I can say. (well... not really: )
Most API's rely on REST or SOAP, which is basically making HTTP request to certain URI's. An example may be
http://api.somewebsite.com/beers.json
Which would return, for instance, a JSON array of certain beers and their properties.
Furthermore, more often than not, you can test API's (that do not require certain HTTP headers for authentication, which makes it harder) by manually constructing the URI's and opening them in your browser. This way, you can verify that your request is okay before you try it in your Rails application an cannot figure out why it's not working.
You should use the 'figaro' gem https://github.com/laserlemon/figaro
It creates a "application.yml" file in which you can add your API key.

Detect user agent in Rails 4 - read HTTP header

I just switched from PHP to Ruby on Rails and was wondering if there was a way to detect the clients device/user agent (reading the HTTP header) in order to serve different versions of the site depending on the request it gets. In PHP I have been using Mobile Detect to do so. The general idea is to only serve files that are needed for each particular version. Thats why a client side approach is not that effective.
Is there a way to do something similar with Ruby 2.0.0 and Rails 4.0.0 ?
Maybe there is a gem to handle cases like that?
Check the request method, where you can get a ActionDispatch::Request where you have all the request parameters, including the user agent.
request.user_agent

How to disable discovery and specify OpenID server for omniauth-openid

I am trying to do OmniAuth OpenID with Google Apps in Ruby on Rails. I know it should work out-of-the-box if I specify ":identifier => 'https://www.google.com/accounts/o8/site-xrds?hd=example.com'" where example.com is the domain that my targeted users come from.
The user can get redirected to Google when accessing /auth/google without a problem, and this openid.identity can be returned from Google:
... &openid.identity=http://example.com/openid?id=xxxxxxxxxxxxxxxxxxxxxxx ...
However, the example.com I am working with does not have the correct "rel='openid2.provider'" <link /> tags set up at http://example.com/, therefore the discovery fails when omniauth-openid tries to check with Google again.
Is there a quick and clean way to work around the default discovery behavior so that I can define https://www.google.com/a/example.com/o8/ud?be=o8 as the server directly without performing the automatic discovery?
Thanks!
I think omniauth-openid uses ruby-openid. If so, you should be able to get it work easily:
gem install ruby-openid-apps-discovery
Then throw in somewhere before making the request
require 'gapps_openid'
Google Apps has a slightly different discovery protocol, which is what that gem provides.
Before using the gem that Steve recommended, I came up with a workaround to make the entire discovery process happen locally only, which I find might be useful to some people. If you only accept users from a single Google Apps domain, you might want to:
Add a line like 127.0.0.1 example.com in your /etc/hosts.
set up a lightweight HTTP server like nginx, create a file called openid (do not append .html), and add your <link rel="openid2.provider" ... > tag there.
This is slightly faster than using ruby-openid-apps-discovery since it saves your application from sending some requests to an external https server.

Sending SMS using Way2sms on rails

Can any one help me to send sms using way2sms api by means of rails application.
Thanks
I have created a free open source SMS API called AlfaSMS API for way2sms,160by2.com,fullonsms. It is available in many programming languages like PHP,VB,C++,c#,Python etc.You can download it from http://www.alfredfrancis.in/alfasms-api/
I have developed an API that anyone can use. Check it out here.
You can use the web page I created or you can use the API. For example, your application can directly forward the request to:
http://ubaid.tk/sms/sms.aspx?uid=99999xxxxx&pwd=12345&msg=YOUR_SMS_MESSAGE&phone=9996669990&provider=way2sms
The different providers are way2sms, fullonsms, smsinside and tezsms.
Works 100%, all the time. :)
Edit: As of 2014, the service is stopped since it violates the TOS of most of these providers.
Cheers.
There is a ruby gem that I wrote based on Ubaid's API. You can find it here.
You can use it in any ruby or rails project as long as you are running a version of ruby >= 1.9.
require 'chagol'
texter = Chagol::SmsSender("9876543210","password","way2sms")
texter.send("9968154700", "Chagol Rocks")
Disclaimer, I am the author of this gem.

Resources