1

我已经构建了一个带有开发依赖项、生成器和供我个人使用的东西的小 Rails 开发工具包。我希望能够在加载 gem 时配置一些东西。对于像 pry-rails 这样的 gem,初始化器执行得太晚了。

所以在项目根目录中使用配置文件会很酷。虽然 Rails 是在我的 gem 加载时定义的,但 Rails.root 返回 nil。如何获得项目根目录?它可以是骇人听闻的东西,它只适用于某些人。

这是我的“初始化程序”,在绝对解决一个项目的配置时效果很好:

class MyDevkit < MonkeyDevkit
  # =======
  # = Pry =
  # =======
  # disable pry components completely
  #disable :pry

  # do not make pry rails default console
  #disable :pry, :console

  # ========
  # = Mail =
  # ========
  # disable mail components completely
  #disable :mail

  # disable letter opener
  #disable :mail, :letter_opener

  # ========
  # = Misc =
  # ========
  #disable :rack_profiler
  #disable :better_errors
  #disable :quiet_assets

  # comment to (temporary) disable the devkit completely
  kitify!
end
4

1 回答 1

2

can you try using Dir.getwd to get current working directory (note: current working dir does not mean your gem's directory. it is a directory that ruby executable was called from), which should be same what you would get from Rails.root (unless some gem changes working dir)

于 2013-01-18T20:40:34.560 回答