如何为每个操作系统设置database.yml条件?

时间:2014-09-05 15:37:59

标签: ruby-on-rails ruby database yaml

我想在Linux和Windows中设置sprocket。在我的database.yml中,如何?

现在:

development:
adapter: mysql2
encoding: utf8
database: skeletor_dev
pool: 25
username: root
password: 
socket: /private/var/mysql/mysql.sock

我想要类似的东西:

development:
  adapter: mysql2
  encoding: utf8
  database: skeletor_dev
  pool: 25
  username: root
  password: 
  socket: /private/var/mysql/mysql.sock if os => windows
  socket: /private/var/mysql/mysql.sock if os => linux

有可能吗?怎么样?

1 个答案:

答案 0 :(得分:0)

使用ERB。

development:
  socket: <%= %w[windows linux].include?(ruby_code_to_get_os) ? '/path/to/sock' : nil %>

显然,您必须弄清楚如何最好地确定平台本身,但这应该让您前进。