Redline Software Inc. - Winnipeg's Leader in Ruby on Rails Development

Redzone Leagues Migration and Updates

Redzone gets a new home

We’ve recently migrated Redzone to a new data center to improve reliability and performance. To keep up to date on the service status please follow us on twitter @redzoneleagues. Leagues with custom domain names have been contacted with the DNS changes you will need to make, but if you are having problems please contact us support@redzoneleagues.com.

User Configurable Statistics

We’ve added support for user configurable statistics. This only applies to stats for certain sports, so you may not see this in use for your league at the moment. Some statistic calculations vary depending on league, so now a league should be able to configure one of the configurable stats to their needs. An example of this is goals against average in hockey; this calculation uses the game length in minutes which could vary between leagues. To see the available statistics options for your league, click on “Statistics Management” under your admin dashboard.

Multiple Active Seasons

Redzone previously had a limitation of one active season at anytime. Many of our leagues were trying to host tournaments during their season or had multiple seasons going on at the same time, so we’ve added support for this. You can setup your seasons under the admin dashboard.

Upcoming Updates

We have additional features in the works, so stay tuned for more frequent updates. If you’d like to comment or make requests for upcoming features, please either leave a comment in the blog or post a message in our forums

CSS Asset Tagger Rails Plugin

We’ve released a new plugin for Rails that adds asset timestamps to assets found in an apps stylesheets.

The plugin is available at http://github.com/redlinesoftware/css_asset_tagger

Simply install the plugin and it will tag any assets in your css files with asset timestamps. More information on asset timestamps can be found at http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html

We wrote a previous article on using asset timestamps with nginx, but similar usage applies to Apache as well for example.

The main purpose for writing this plugin is that stylesheets that use images for various things don’t get tagged with the asset timestamps when they’re written as plain old css files. These images can’t make use of expiration techniques very easily without the timestamps. So to make things work as they do with images in rails views, this plugin will add the same timestamps to assets in css files as they are in rails views.

Before…

1
2
3
#navigation_bar {
  background-image: url(/images/background-nav.png);
}

After…

1
2
3
#navigation_bar {
  background-image: url(/images/background-nav.png?1234567890);
}

If you’re using yslow and some decent expiration on the server and you don’t like seeing images from your css files being shown in your report card, this plugin should make those all go away and hopefully give you a better grade. :)

Lacrosse Support in Redzone

We’ve added support for Lacrosse to Redzone. If you or somebody you know has a Lacrosse league, sign up and check it out.

Quick update to hockey; we’ve added support for +/- stats as well.

Redzone Updates: Multiple Positions and Team Statistics

We’ve just deployed some major updates to Redzone’s statistics. These include support for multiple positions as well as team related statistics in addition to the player statistics that were only supported before.

We’ve added new statistics to some of the sports, so you check for those in the “Statistics Management” section of the admin dashboard. If there are statistics that you don’t see, but would like to see added then just send us an email at support@redzoneleagues.com and let us know what additional stats you would like to see.

The game cards haven’t been updated to support the addition of multiple positions yet, but this will be supported in an upcoming release. If your league doesn’t track stats for more than one position then you’ll be fine with the current game cards.

We’ve made some changes to the standings calculations. Points can now be awarded to teams for Overtime losses. This is a common theme in hockey where shootouts occur.

The forums display a users profile picture (avatar) along with their post count.

Other minor changes and fixes have been made as well and we have a few more quick updates coming in the next few weeks; mainly the addition of some new statistics.

Since this is fairly large update, there may be some minor issues that may appear, so if you notice any inconsistencies or issues with any of the statistic values, please let us know and we’ll correct the issues as soon as we can. You can do so by posting a message in our forums or by sending us an email.

Silencing DB Messages During Tests

When running tests in Rails, sometimes you need to perform various tasks in the database directly which can lead to a lot of unwanted messages in your test output.

If you’re using Postgresql, simply add the following line to your tests/tests_helper.rb file.

1
ActiveRecord::Base.connection.execute "set client_min_messages to ERROR"

Now you’ll only see messages of ERROR and above in your test output.

Update

Found a better way to do this. In your database.yml file, simply add the following line to your :test section.

1
  min_messages: ERROR

Plugins Moved to Github

We finally got around to moving our plugins from our old SVN machine into Github. Although we’ve been using Git for a long time, we were slow on moving our plugins for some reason.

github.com/redlinesoftware

Team Registration Changes

A minor change has been made to Redzone Leagues with regards to the team signup process. When a user registers a team, they will now receive an confirmation email with an activation link that they will need to load in order to complete the registration process.

The reason for this change was to ensure that team representatives have current email addresses entered into the system. League administrators often need to contact team representatives, so we want to make sure those emails are as current as possible. As always, users can update their email address by clicking “My Profile” at the top of the site. If they need to resend a team activation email, they can do so from their “My Teams” page, which is linked at the top of the site after they create a team.

If you are a league administrator adding a new team, you will not need to complete the activation process. This is done to make the team creation by administrators as quick as possible.

Extending Named Scopes

Quick code tip…

I’m using named_scope with a lambda as the 2nd paramater, but I also want to extend the named_scope with some custom methods.

1
2
3
4
5
6
named_scope :for_league, lambda{|league_id| {league conditions} } do
  def default
  end
  def do_something_custom
  end
end

I use the same extended methods in more than one place, so I figured I’d use something similar to the :extend option used with association methods like has_many, but I can’t pass an :extend option if I’m also using a lambda.

The way around this is to just include the methods directly in the block.

1
2
3
4
5
6
7
8
9
10
module Associations
  def default
  end
  def do_something_custom
  end
end

named_scope :for_league, lambda{|league_id| {league conditions} } do
  include Associations
end

Works like a charm. Now I can just reuse the Associations module where I need it.

Nginx Expiry for Ruby on Rails

Many examples I see for setting the expiry header with Nginx look something like this…

1
2
3
4
5
6
location ~* (stylesheets|javascripts|images) {
  if (-f $request_filename) {
    expires max;
    break;
  }
}

This example runs a regex against the location of the incoming query for a path that contains one of the rails asset types. If the requested file exists then the expiry header is set. max here just tells the server to set the expiry date to the maximum value possible. You can set it to 10 years or any number of days if you prefer.

The issue with this is approach is that it is a “catch all” and ignores the query string on an asset if one exists. Both /stylesheets/styles.css?1234567890 and /stylesheets/styles.css are treated the same using this method of expiry.

If an asset is retrieved from the server (query string or not) and the expires header is set, the next time the file is referenced in the browser, the file will be loaded from the browser cache instead of the server. Now if the asset is modified on the server, rails will update the query string and the browser will recognize the difference and re-fetch it from the server. For the assets that don’t have an associated query string (like /stylesheets/styles.css), the browser will have no idea anything has changed and still load the file from it’s cache. This can cause styles or scripts to go out of sync between the server and the browser causing some nasty issues for the user.

So essentially, we only want to set the expires header on the assets that have a query string and not set the expires header on assets that don’t have one. This way the browser will always retrieve the most up to date version of a file.

What we’re looking for are 2 conditions that need to be satisfied before we set the expires header:

  1. The file is one of the asset types
  2. The query string contains the 10 digit timestamp

So let’s update the config to only set the expires header on asset files that have the 10 digit query string.

1
2
3
4
5
6
7
8
9
location ~* (stylesheets|javascripts|images) {
  if (!-f $request_filename) {
    break;
  }
  if ($query_string ~* "^[0-9]{10}$") {
    expires max;
    break;
  }
}

Here we use the same regex as before to find one of the asset types, but now instead of checking if the file exists, we check if it doesn’t exist. If the file doesn’t exist, we break out and don’t set the expires header which is fine. If the file does exist, then we don’t break, but continue evaluating our conditions because we’ve now satisfied condition 1 as we are looking at one of our asset files. The next thing we do is check the query string for a 10 digit pattern. If the check is successful then we’ve also satisfied condition 2 and can set the expires header for the file.

Now when we update an asset file on the server and Rails updates the query string, the server will re-fetch the file and set a new expires value… perfect.

If you want to check the file extension instead of their directories, you can use the following configuration instead. Note the location regex change.

1
2
3
4
5
6
7
8
9
location ~* \.(js|css|jpg|jpeg|gif|png)$ {
  if (!-f $request_filename) {
    break;
  }
  if ($query_string ~* "^[0-9]{10}$") {
    expires      max;
    break;
  }
}

Player Data and OT Pts

Two new features have been added to Redzone.

  1. You can now download your player data from the admin users page. The file can be imported into a spreadsheet and formatted however you see fit.
  2. A new overtime win point setting has been added along with the other point settings which are available from the admin dashboard.