我在application_controller.rb中定义了一个$template变量,其中包含一些通过admin更改的站点模板代码
问题是当我保存或更新它时,它不会影响站点直到服务器重启,这在生产中真的很不舒服
$template = Template.first ..... $template.header.html_safe在日志中,我可以使用那个$ template变量make和SQL以及最开始(在Puma启动之前),这可能是全局变量应该如何工作的方式。
PS我使用active_admin并从那里更新
I have an $template variable defined in application_controller.rb which contains some site template code changed though admin
The problem is when I save or update it, it doesn't affect site till server restart, which is really uncomfortable in production
$template = Template.first ..... $template.header.html_safeIn logs I can the that $template variable make and SQL and the very beginning (before Puma booted) and probably that's the way how global vars should be working.
P.S. Im using active_admin and update from there
最满意答案
这是因为你获取你的Template并且它在内存中,因此在每次save (:create,:update,create!,:update!,:save,:save!)之后你必须重新加载你的变量
$template.reload这将更新您的变量
或者你可以只在你的ApplicationController添加辅助方法
def first_template Template.first end helper_method :first_template这将每次检索更新的数据
你可以在你的视图中使用它
first_template.header.html_safeit is because you fetch your Template and it is in memory, so after each save (:create, :update, create!, :update!, :save, :save!) you have to reload your variable
$template.reloadthis will update your variable
or you can just add helper method to your ApplicationController
def first_template Template.first end helper_method :first_templatethis will retrieve updated data each time
and you can use it in your view
first_template.header.html_safe更多推荐
发布评论