Skip to content

Instantly share code, notes, and snippets.

@woods
Created January 8, 2015 14:40
Show Gist options
  • Save woods/4d4af26fb91f51d73c72 to your computer and use it in GitHub Desktop.
Save woods/4d4af26fb91f51d73c72 to your computer and use it in GitHub Desktop.
An example of a helper for determining which instance/flavor we're running.
# A helper for determining which partner site we're on. This can be
# used for setting a CSS class on the body tag in the layout, or
# for referencing namespaced assets or translations.
def parner(host=request.host)
if $ENV['PARTNER'] == 'graduate' || host =~ /graduate/i
'graduate'
elsif $ENV['PARTNER'] == 'schreyer' || host =~ /schreyer/i
'schreyer'
else
# decide whether to fail or default to one of the above
end
end
@woods
Copy link
Author

woods commented Jan 10, 2015

Interesting. Yeah. You're really making me reconsider this…

I could totally see where perhaps you'd never want to do URL matching; where instead you'd always want it to be a conscious decision via a required environment variable. The README would instruct you to start your development rails server with an ENV. And the error message if it's not set could be very instructive.

Perhaps our URL matching was born out of a desire for convenience, and perhaps that's misplaced.

Good food for thought!

@woods
Copy link
Author

woods commented Jan 10, 2015

def partner
  ENV['partner'] or raise "You must set the PARTNER environment variable to either 'graduate' or 'schreyer'"
end

Perhaps that would be more robust. Then our servers would be locked in too. They're currently relying on URL matching, and now that I'm giving it more thought, that does seem kind of unnecessarily flimsy.

@woods
Copy link
Author

woods commented Jan 10, 2015

And it doesn't stop a developer from having two browser windows open with a different partner running in each one. You just have to fire up separate servers for each environment variable (on different port numbers).

@woods
Copy link
Author

woods commented Jan 10, 2015

Although it is a little less slick than just being able to symlink and open http://schreyer.dev/ ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment