我正在为应用创建自定义模板,并添加了pg而不是sqlite来使用:
gem 'pg'
gsub_file "Gemfile", /^gem\s+["']sqlite3["'].*$/,''
after_bundle do
generate "rspec:install"
generate "simple_form:install"
end
但是,如果我这样创建应用程序(默认情况下将为sqlite3配置的database.yml文件),那么如何postgresql
从模板中指定要为其添加配置的应用程序呢?就像我添加--database=postgresql
选项一样
不需要向用户询问应用程序名称,因为app_name
已经填充了该名称。
Thor命令对于处理文件非常有用,可以使用.erb
模板,并使用template方法从模板传递它们的值:
# config the app to use postgres
remove_file 'config/database.yml'
template 'database.erb', 'config/database.yml'
database.erb:
default: &default
adapter: postgresql
host: db
port: 5432
pool: 5
timeout: 5000
user: postgres
password: postgres
development:
<<: *default
database: <%= app_name %>_development
test:
<<: *default
database: <%= app_name %>_test
production:
<<: *default
database: <%= app_name %>_production
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句