Portal Labs, LLC Logo
Custom Web Design and Application Development

Fixing subdomain_fu With Named Routes (Rails 2.2)

December 2nd, 2008

We recently upgraded our project that was using subdomain_fu to rails 2.2 and the previous fix no longer works.

Turns out the solution is even easier in rails 2.2 than 2.1. Open up lib/subdomain_fu/routing_extensions.rb and put this bit of code at the very bottom:


ActionController::UrlRewriter::RESERVED_OPTIONS << :subdomain

Is this the correct way? Doesn’t seem to be since we’re modifying a “constant”, but it seems to work.

Free Wordpress Theme: WP-PortalTheme

November 27th, 2008

WP-PortalTheme OrangeWP-PortalTheme Orange is the first free theme released by Portal Labs. It is a lightweight, XHTML Valid, 2-column, fixed width theme in a pretty shade of orange (our signature color).

It is widget ready and features a 2×2 ad block in the right sidebar for up to 4 125×125 banner ads.

In future versions we plan to include a theme options page with color scheme picker and an assortment of additional color schemes complete with header graphic and styles.

Check out the live theme preview and download it at the Wordpress Themes directory: WP-PortalTheme Orange Download

Fixing subdomain_fu With Named Routes

October 22nd, 2008

subdomain_fu is a great little plugin for rails to make managing multiple subdomains easier.  Watch the railscast and try it out for yourself.

Unfortunately, it didn’t handle named routes with the :subdomain parameter correctly.  You can learn more about this bug over at the subdomain_fu lighthouse bug tracker.  The ticket has been open for several months now with no hint at a solution coming anytime soon.

The fix is pretty simple.  Kudos go to ticket #4 for the solution.  Open up vendor/plugins/subdomain-fu/lib/subdomain_fu/url_rewriter.rb and add the following to the bottom of the ActionController module:


module Routing
    module Optimisation
      class PositionalArgumentsWithAdditionalParams
        def guard_condition_with_subdomains
          # don't allow optimisation if a subdomain is present - fixes a problem
          # with the subdomain appearing in the query instead of being rewritten
          # see http://mbleigh.lighthouseapp.com/projects/13148/tickets/8-improper-generated-urls-with-named-routes-for-a-singular-resource
          guard_condition_without_subdomains + " && !args.last.has_key?(:subdomain)"
        end

        alias_method_chain :guard_condition, :subdomains
      end
    end
  end

Restart your rails server and everything should start to work correctly for you.

Client DropBox   |   Client Login