有没有办法让我的自定义佣金任务仅列在development
环境中,而不是production
和QA
中?
我的意思是,当我在bundle exec rake -T
或qa
env中调用production
时,它不应该列出我的自定义rake tasks
,但它应该在development
中。< / p>
答案 0 :(得分:3)
您可以将其添加到应用Rakefile
(MyRailsApp::Application.load_tasks
行之后):
if Rails.env == "production"
# add here the tasks you want to disable
tasks_to_disable = [
"db:drop",
"db:reset"
]
tasks = Rake.application.instance_variable_get("@tasks")
tasks.delete_if { |task_name, _| tasks_to_disable.include?(task_name) }
end