Infinite Loop with Force_SSL

I ran into an issue where I keep getting infinite loops on views with force_ssl.  I’m using Nginx and found that I needed to adjust the config.

For me the settings were in /etc/nginx/sites-enabled/default.

I needed to add this in the @location part:

proxy_set_header X_FORWARDED_PROTO $scheme;

Here's how my file ended up looking:

server {
    listen   443;
    ssl on;
    ssl_certificate     /etc/ssl/xyz.crt;
    listen   80;
    root /home/rails/public;
    server_name _;
    index index.htm index.html;

    location / {
            try_files $uri/index.html $uri.html $uri @app;

#       location ~* ^.+\.     (jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rt    f|js|mp3|flv|mpeg|avi)$ {
location ~* ^.+\.    (jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp    3|flv|mpeg|avi)$ {
                    try_files $uri @app;

     location @app {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http://app_server;
            proxy_set_header X_FORWARDED_PROTO $scheme;


It has not been a picnic using RSpecs.  One of the steeper learning curves I’ve found in Rails.  Here are some random tidbits I’ve found:

(1)  the rspec command doesn’t get recognized in Windows for me.  So I have to do: rake spec:controllers (or whichever folder)

(2) to run a single test, from the root directory, do:

bundle exec rspec spec/(path to file).rb


bundle exec rspec spec/controllers/user_controller_spec.rb

Caching Rails 3 on Heroku

To learn about caching, I used a few different resources.

The three basic types of caching are:

  • page caching – mainly for static pages, it will not work if any filters are applied to the controller of the page (ie authorizations)
  • action caching – typically what you’d used to cache a page if they have filters
  • fragment caching – allows for caching of blocks of html on a page (if you can’t cache the whole page) or for partials

Since I’m on Heroku, the first place to learn was Heroku’s documentation.  It’s important to read the Heroku docs first because some standard Rails functions work differently on Heroku’ platform.  Mainly, for page caching (uses different syntax than standard rails) and action caching (mostly dependent on memcache, so you need to set your app up accordingly).

Overview of caching on Heroku

There’s also a Rails Guide on Caching (just remember to ignore page caching part):

However, the most extensive (and useful) one for me was from Adam Hawkins at (especially for fragment caching):

I also needed to learn about sweepers, in order to observe for changes that would impact another controller’s pages.  This Stack Overflow post helped me learn to put the sweeper in with the models and to ensure that I updated the correct controller: