Rails: Per-environment initializers?

后端 未结 3 532
臣服心动
臣服心动 2020-12-15 03:16

I\'d like the code in one of my initializers (in config/initializers/) to be run only for the :development environment, but not :test

相关标签:
3条回答
  • 2020-12-15 03:45

    I'm pretty sure your only two options are putting the configuration code in config/environments/development.rb or wrapping your initializer code with your if block. You can tighten up your second option by doing if Rails.env.development?, though.

    0 讨论(0)
  • 2020-12-15 03:47

    Barista has a config setting for this:

    Barista.configure do |c|
      c.env = :development
    end
    

    This will only recompile coffescript into js in dev mode and should speed up your tests.

    Make sure you run:

    rake barista:brew
    

    before checking your code in.

    https://github.com/Sutto/barista

    0 讨论(0)
  • 2020-12-15 03:53

    I don't know if this is a good idea, but it's a different idea.

    You could create a config/initializers/development directory (or config/environments/development/initializers), put your barista_config.rb in that directory, and then include anything in that directory from config/environments/development.rb.

    I don't know if that's a good idea or not but it's at least a third option...just in case you're still thinking about this problem three and a half years after asking the question.

    0 讨论(0)
提交回复
热议问题