How to auto-reload changes in a Rails Engine?

一个人想着一个人 提交于 2019-12-10 12:46:30

问题


I have a Rails 4.1.0 mountable engine. In the engine's application_helper.rb:

module MyEngine
  module ApplicationHelper    
    def test123
      "test123"
    end    
  end
end

The method is in the dummy app's view general/index.html.erb view:

%<= test123 %>

This works. However, when I change the string returned by def test123 and refresh the browser, the new string is not displayed.

Of course, restarting the web server in the dummy app shows the new string.

So the question is, how to reload the engine's files without having to restart the web server?

PS. I am preferably looking for a way to do this using Rails itself, or a specific gem that solves this problem (but not the generic gems like Guard, Spork etc. although if all else fails, I will consider those too.)

PPS. There are similar questions on SO, but I have tried them all (even though they are for Rails 2.x, 3.x), and they have not worked for me.


回答1:


You should explicitly require dependent helpers:

# engines/my_engine/app/controllers/my_engine/application_controller.rb

require_dependency "my_engine/application_helper"  # This is a key point!

module MyEngine
  class ApplicationController < ::ApplicationController
    helper ApplicationHelper
    ...



回答2:


you can use some thing like zeus which is helping a lot in watching project files for changes except in some cases when you change the configuration files it doesn't work and needs to be manually restarted.

but overall in most cases this works more than awesome



来源:https://stackoverflow.com/questions/20172106/how-to-auto-reload-changes-in-a-rails-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!