I am writing a template for Rails 3 (you can find it here), and I’m having troubles with the following lines:
# 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
That is, the first inject_to_file works, and in config/database.yml I have
development:
host: /var/run/postgresql
but the other two inject_to_file are successfully applied, but don’t modify config/database.yml! So I have
test:
adapter: postgresql
and
production:
adapter: postgresql
You have to specify the
:force => trueoption to inject the same text multiple times.See:
http://rdoc.info/github/wycats/thor/master/Thor/Actions#insert_into_file-instance_method
This version works for me:
https://gist.github.com/2573325
Don’t ask me why that option makes any sense, tho.