Posted By

lfatr on 07/02/10


Tagged

railsforum


Versions (?)

a ruby on rails widget


 / Published in: Rails
 

URL: http://www.railsforum.com/viewtopic.php?id=737

  1. module WidgetsHelper
  2. def recent_topics_widget(limit = 5)
  3. topics = Topic.find(:all, :order => 'created_at DESC', :limit => limit)
  4. render :partial => 'widgets/recent_topics', :locals => { :topics => topics }
  5. end
  6.  
  7. # all other widgets go here
  8. end
  9.  
  10. # in application.rb
  11. helper :widgets # loads the WidgetsHelper for all views
  12.  
  13. # in views/widgets/_recent_topics.rhtml
  14. <div id="recent_topics" class="widget">
  15. <% for topic in topics %>
  16. <div class="topic"><%= topic.name %></div>
  17. <% end %>
  18. </div>

Report this snippet  

You need to login to post a comment.