我写了一个插件来抓取最新的问题并在主页上显示它们。所有这些似乎都运行良好,但它只在我第一次重新启动服务器运行它时起作用 - 之后它会缓存'从那时起的问题,没有新的问题得到解决。
我已经阅读过一些关于它的内容,似乎我应该编写一个补丁来解决在我的插件中添加额外功能的问题。真的吗?如果是,我应该在after_save
行动中添加什么?对于LatestPostsSetup模型也是如此 - 如果我更改了应该显示的最大计数和侧面的值,主页在我重新启动服务器之前不会反映它。
很抱歉,如果这个问题看起来相当微不足道,那我就是ruby的新手。请在下面找到视图帮助代码:
module LatestPosts
class ViewHookListener < Redmine::Hook::ViewListener
require 'plugins/latest_posts/app/models/latest_posts_setup.rb'
setup = LatestPostsSetup.find_by_id(1)
if setup == nil
count = LatestPostsSetup::DEFAULT_COUNT
side = LatestPostsSetup::DEFAULT_SIDE
else
count = setup.max_count
side = setup.side
end
issues = Issue.find(:all, :limit => count, :order => "created_on DESC")
if side == 'left'
render_side = :view_welcome_index_left
else
render_side = :view_welcome_index_right
end
render_on render_side, :locals => {:issues => issues}, :partial => "latest_issues/issues"
end end
编辑
我现在已经更改了视图助手以动态呈现html,并且我不必重新启动apache以显示新问题,我不明白为什么这会影响使用一个HTML模板? 请找到以下代码:
# lib/latest_posts_hook_listener.rb
module LatestPosts
class ViewHookListener < Redmine::Hook::ViewListener
def view_welcome_index_left(context={})
setup = load_setup()
if setup[:side] == "left"
load_issues(setup[:count])
end
end
def view_welcome_index_right(context={})
setup = load_setup()
if setup[:side] == "right"
load_issues(setup[:count])
end
end
def load_setup()
require 'plugins/latest_posts/app/models/latest_posts_setup.rb'
setup = LatestPostsSetup.find_by_id(1)
if setup == nil
count = LatestPostsSetup::DEFAULT_COUNT
side = LatestPostsSetup::DEFAULT_SIDE
else
count = setup.max_count
side = setup.side
end
{:count => count, :side => side}
end
def load_issues(count)
html = '<div class="box" id="statuses">'
html += '<h3 class="icon22 icon22-users">Latest Issues</h3><ul>'
issues = Issue.find(:all, :limit => count, :order => "created_on DESC")
issues.each do |issue|
html += <<EOHTML
<li>
#{link_to h(truncate(issue.subject, :length => 60)), :controller => 'issues', :action => 'show', :id => issue } (#{ format_date(issue.created_on) })
</li>
EOHTML
end
html += '</ul></div>'
return html
end
end
end