Fixing subdomain_fu With Named Routes
Wednesday, October 22nd, 2008subdomain_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.
