1

私は 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

他の 2 つの inject_to_file は正常に適用されますが、config/database.yml を変更しないでください。ので、私は持っています

test:
  adapter: postgresql

production:
  adapter: postgresql
4

2 に答える 2

4

:force => true同じテキストを複数回挿入するオプションを指定する必要があります。見る:

http://rdoc.info/github/wycats/thor/master/Thor/Actions#insert_into_file-instance_method

このバージョンは私のために動作します:

https://gist.github.com/2573325

なぜそのオプションが意味をなすのか私に聞かないでください。

于 2012-05-02T03:18:49.080 に答える