404 images and assets in Rails 3.2

For folks that have come from a traditional web dev background they may think that putting an image “example.jpg” into the /assets/images folder might be accessed via a url mirroring that path e.g. “www.domain.com/assets/images/example.jpg”.  I spent 10 minutes noobishly confused until I realised that you don’t specify the /images/ part of the path in the url.  So the above example would be served up on “http://www.domain.com/assets/example.jpg” even though the image is in the images folder.  I’m using Rails 3.2.

When debugging this the server is (obviously) returning a 404 for the image file and if you try to browse to the image directly rails returns a route not defined error.


OmniAuth Google OAuth2 strategy – where to get Google Key and Secret

Having spent too much time ironically on Google searching for how to obtain a Google Key and Google Secret (for OAuth2) I decided to post this for future reference.

I’m assuming that you are implementing some Google authentication functionality with something like OmniAuth (Ruby on Rails gem).  Whether it is OmniAuth or not you’ll need to register your application with Google; obtaining a Google Key and Google Secret as well as setting a callback url.

  1. Go to https://code.google.com/apis/console, log in with your Google account and click on API Access.
  2. Create OAuth2 credentials by clicking the big blue OAuth2 button.
  3. Set the callback url and the name of your app (can be edited later)
  4. The Google Key (as it is referred to by OmniAuth) is the Client ID
  5. The Google Secret (as it is referred to by OmniAuth) is the Client Secret
  6. Use those credentials as per your documentation for implementing OAuth2 authentication.

The Google OmniAuth strategy for OAuth2 is here: https://github.com/zquestz/omniauth-google-oauth2.  Look in the examples folder for details on the rest of the implementation.