title: Redmine plugin view hook refresh when issues change
body: <p>I wrote a plugin that grabs latest issues and displays them on the home page. All seems to work pretty well, but it only works the first time I restart the server to run it - after that it 'caches' the issues from that time, and no new ones get fetched. </p>
  
  <p>I've been reading a bit about it, and it seems that I should write a patch for issues to add extra functionality in my plugin. Is that true? If so, what should I add to <code>after_save</code> action? The same happens for the LatestPostsSetup model - if I change the values for max count and side on which it should be displayed, home page doesn't reflect it until I restart the server.</p>
  
  <p>Sorry if this questions seems fairly trivial, I'm new to ruby. Please find the view helper code below:</p>
  
  <pre><code>module LatestPosts
      class ViewHookListener &lt; 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 =&gt; count, :order =&gt; "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 =&gt; {:issues =&gt; issues}, :partial =&gt; "latest_issues/issues"
      end end
  </code></pre>
  
  <p><strong>EDIT</strong> </p>
  
  <p>I have now changed the view helper to render the html on the fly, and I don't have to restart apache for the new issues to be displayed, I don't understand why would that work over using a html template?
  Please find the code below:</p>
  
  <pre><code># lib/latest_posts_hook_listener.rb
  module LatestPosts
      class ViewHookListener &lt; 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 =&gt; count, :side =&gt; side}
          end
  
          def load_issues(count)
              html = '&lt;div class="box" id="statuses"&gt;'
              html += '&lt;h3 class="icon22 icon22-users"&gt;Latest Issues&lt;/h3&gt;&lt;ul&gt;'
              issues  = Issue.find(:all, :limit =&gt; count, :order =&gt; "created_on DESC")
              issues.each do |issue|
                  html += &lt;&lt;EOHTML
                    &lt;li&gt;
                        #{link_to h(truncate(issue.subject, :length =&gt; 60)), :controller =&gt; 'issues', :action =&gt; 'show', :id =&gt; issue } (#{ format_date(issue.created_on) })
                     &lt;/li&gt;
  EOHTML
              end
              html += '&lt;/ul&gt;&lt;/div&gt;'
              return html
          end
      end
  end
  </code></pre>