【问题标题】:How can I comment a line using thor from a Rails 3 Template?如何使用 Rails 3 模板中的 thor 评论一行?
【发布时间】:2012-01-27 17:48:03
【问题描述】:

我想在我的 Rails 3 模板中使用 thor 注释文件 (spec_helper.rb) 中的一行?

来自:

  config.fixture_path = "#{::Rails.root}/spec/fixtures"

# config.fixture_path = "#{::Rails.root}/spec/fixtures"

我知道我可以使用inject_into_file 向文件中注入一行,但我想注释指定文件中的一行。

谢谢!

【问题讨论】:

    标签: ruby-on-rails-3 thor


    【解决方案1】:

    您可以使用 Thor Action gsub_file

    文档中的示例

    gsub_file 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1'
    

    您必须根据需要调整正则表达式和替换字符串,但这应该是可能的。

    【讨论】:

      猜你喜欢
      • 2011-03-26
      • 1970-01-01
      • 1970-01-01
      • 2011-11-17
      • 1970-01-01
      • 2012-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多