Skip to content

Instantly share code, notes, and snippets.

@dpickett
Created April 4, 2011 01:30
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save dpickett/901023 to your computer and use it in GitHub Desktop.
Save dpickett/901023 to your computer and use it in GitHub Desktop.
if Rails.env.production?
Braintree::Configuration.environment = Rails.env.staging? ? :sandbox : :production
Braintree::Configuration.merchant_id = ENV["braintree_merchant_id"]
Braintree::Configuration.public_key = ENV["braintree_public_key"]
Braintree::Configuration.private_key = ENV["braintree_private_key"]
else
Braintree::Configuration.environment = :sandbox
Braintree::Configuration.merchant_id = "<super secret>"
Braintree::Configuration.public_key = "<super secret>"
Braintree::Configuration.private_key = "<super secret>"
end
@hoverlover
Copy link

I think there is a mistake in your example:

if Rails.env.production?
  Braintree::Configuration.environment = Rails.env.staging? ? :sandbox : :production
  ...
else
  ...
end

Shouldn't that line just be

Braintree::Configuration.environment = :production

There can only be one active environment at any given time.

@dpickett
Copy link
Author

no that's a ternary operator basically if the equivalent of

  if Rails.env.staging?
    Braintree::Configuration.environment = :sandbox
  else
    Braintree::Configuration.environment = :production
  end

@hoverlover
Copy link

I'm well aware of the ternary operator. Maybe you didn't see this part of my comment:

There can only be one active environment at any given time.

If execution falls through the if Rails.env.production? branch, Rails.env.staging? will always return false, right? So in your gist, :production would always be the outcome. That's why I said you might as well just hard-code it to :production.

@hoverlover
Copy link

Sorry, made a typo in my previous comment. I've updated it.

@paulrnash
Copy link

hoverlover is correct, this would not actually work right. Saying "if not Rails.env.test?" in the first check would give the effect the author wants.

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