Tag: prepend

rails prepend_view_path可安装引擎

一方面,我有一个可安装的引擎让我们说Front Front包含我的资产和几页它与MainApp隔离。 我不希望它触及主应用程序。 另一方面,我希望我的MainApp使用布局和Front的部分。 所以我这样设置布局: class ApplicationController < ActionController::Base layout 'front/application' end 但是前端/应用程序直接引用引擎部分,因为隔离,就像这样 render ‘header’ # front/ prefix is not required 因此,MainApp视图尝试加载app / views / application / header而不是app / views / front / application / header 为了解决这个问题,我把prepend_view_path放到这样: class ApplicationController < ActionController::Base layout 'front/application' before_filter :prepend_front protected def prepend_front prepend_view_path "app/views/front" end end 但这不起作用,因为引擎路径指向供应商。 引擎将它自己添加到前置路径列表:〜/ main_app […]

使用Ruby在文件前面添加一行

我想用Ruby添加一行到Ruby的文件顶部: # initial file contents something else # file contents after prepending “hello” on its own line hello something else 以下代码只是替换整个文件的内容: f = File.new(‘myfile’, ‘w’) f.write “test string”