我正在为 Rails 3 编写一个模板(你可以在这里找到它),我遇到了以下几行的问题:
# 8. config/database.yml modifications
if yes?("Do you want to set the database host to '/var/run/postgresql'?")
inject_into_file "config/database.yml", " host: /var/run/postgresql\n", :after => "development:\n"
# FIXME these two won't work :(((( why????
# inject_into_file "config/database.yml", " host: /var/run/postgresql\n", :after => "production:\n"
# inject_into_file "config/database.yml", " host: /var/run/postgresql\n", :after => "test:\n"
# Not finding other solutions, I rewrite the two blocks above with two seds
run %q(sed -i '/test:/a\ \ host: /var/run/postgresql' config/database.yml)
run %q(sed -i '/production:/a\ \ host: /var/run/postgresql' config/database.yml)
end
也就是说,第一个 inject_to_file 有效,并且在 config/database.yml 我有
development:
host: /var/run/postgresql
但是其他两个inject_to_file都申请成功了,但是不要修改config/database.yml!所以我有
test:
adapter: postgresql
和
production:
adapter: postgresql