mko
mko

Reputation: 22114

How to define different variable in both development environment and production environment?

like the remote server and port number, It's really annoying to change back and forth, I noticed there's a

set :environment, :production/:development 

configuration option for sinatra, but I don't know how to set different variable to each mode

Upvotes: 0

Views: 171

Answers (2)

Frank
Frank

Reputation: 143

If your settings are few:

For classic Sinatra apps:

port = 4567 if development?
port = 80 if production?

For modular Sinatra apps:

port = 4567 if Sinatra::Base.environment == :development
port = 80 if Sinatra::Base.environment == :production

But if you have several environment dependent settings, using three's suggestion above is cleaner:

configure :development, :test do
  port = 4567
  url = "https://secure.appname.com"
  ...
end

Upvotes: 0

three
three

Reputation: 8488

you can have something like this:

configure :development do
  set :this
end

configure :production do
  set :that
end

Upvotes: 1

Related Questions