我目前正在尝试将功能移入引擎。到目前为止,它运作得很好,但是我有点困惑为什么引擎的某些部分在更改时会自动重新加载,而另一些则不会。
具体来说,在添加帮助程序方法时,我必须重新启动Rails服务器,否则Rails将无法看到它。这是正常行为吗?这是我的引擎的相关部分:
components/iq_list.rb
# encoding: utf-8
require 'iq_list/engine'
# Load IqList Modules
module IqList
extend ActiveSupport::Autoload
autoload :Helpers
autoload :Models
autoload :Controllers
end
组件/iq_list/engine.rb
module IqList
class Engine < ::Rails::Engine
end
end
组件/ iq_list / helpers.rb
module IqList
module Helpers
extend ActiveSupport::Autoload
autoload :IqListHelper
end
end
组件/iq_list/helpers/iq_list_helper.rb
module IqList
module Helpers
module IqListHelper
def some_method
# ...
end
end
end
end
我对引擎还非常陌生,上面的很多代码都是我从别人的作品中借鉴来的,请耐心等待。任何指向正确方向的提示都将不胜感激。
app/components
中,东西得到了适当的重新加载。如果你正在开发一个引擎,你会把它放在哪里? - Joshua Muheimvendor/engines
目录下,它应该会自动加载。请参考(文档)[http://guides.rubyonrails.org/engines.html] 了解如何开始使用引擎。 - leenasn