Guest User

Untitled

a guest
Feb 21st, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. Index: app/models/forum.rb
  2. ===================================================================
  3. --- app/models/forum.rb (revision 2428)
  4. +++ app/models/forum.rb (working copy)
  5. @@ -1,5 +1,6 @@
  6. class Forum < ActiveRecord::Base
  7. - acts_as_list
  8. + acts_as_list :scope => :parent_id
  9. + acts_as_tree
  10.  
  11. validates_presence_of :name
  12.  
  13. Index: app/controllers/forums_controller.rb
  14. ===================================================================
  15. --- app/controllers/forums_controller.rb (revision 2428)
  16. +++ app/controllers/forums_controller.rb (working copy)
  17. @@ -3,7 +3,8 @@
  18. before_filter :find_or_initialize_forum, :except => :index
  19.  
  20. def index
  21. - @forums = Forum.find(:all, :order => "position")
  22. + # only 1 level of children due to limitations of acts_as_tree (unless we do a lot more sql)
  23. + @forums = Forum.find(:all, :conditions => 'parent_id IS NULL').collect{ |f| [f, f.children] }.flatten
  24. end
  25.  
  26. def show
  27. Index: app/views/forums/_form.rhtml
  28. ===================================================================
  29. --- app/views/forums/_form.rhtml (revision 2428)
  30. +++ app/views/forums/_form.rhtml (working copy)
  31. @@ -16,6 +16,16 @@
  32. </table>
  33.  
  34. </p>
  35. -<p id="forum_descripion">
  36. +
  37. +<p id ="forum_category">
  38. +<%= f.check_box :category %><label>Category only</label>
  39. +</p>
  40. +
  41. +<p id ="forum_parent_id">
  42. +<label>Parent forum/category (blank for root)</label><br />
  43. +<%= f.select :parent_id, Forum.find(:all, :conditions => 'parent_id IS NULL').collect {|o| [ o.name, o.id ] }, { :include_blank => true } %>
  44. +</p>
  45. +
  46. +<p id="forum_description">
  47. <label>Description</label><br />
  48. <%= f.text_area :description, :rows => 7 %></p>
  49. \ No newline at end of file
  50. Index: app/views/forums/index.rhtml
  51. ===================================================================
  52. --- app/views/forums/index.rhtml (revision 2428)
  53. +++ app/views/forums/index.rhtml (working copy)
  54. @@ -8,7 +8,7 @@
  55.  
  56. <% if admin? %>
  57. <h6>Admin</h6>
  58. -<p><%= link_to 'Create New Forum', new_forum_path, :class => "utility" %></p>
  59. +<p><%= link_to 'Create New Forum/Category', new_forum_path, :class => "utility" %></p>
  60. <% end %>
  61.  
  62. <% end %>
  63. @@ -32,6 +32,19 @@
  64. </tr>
  65. <% for forum in @forums do %>
  66. <tr>
  67. + <% if forum.category -%>
  68. + <td class="vat c1">
  69. + </td>
  70. + <td class="c2" colspan=2>
  71. + <%= link_to "Edit", edit_forum_path(forum), :class => "tiny", :rel => "directory", :style => "float:right" if admin? %>
  72. + <div class="title">
  73. + <%= forum.name %>
  74. + </div>
  75. + <p class="desc">
  76. + <%= forum.description_html %>
  77. + </p>
  78. + </td>
  79. + <% else -%>
  80. <td class="vat c1">
  81.  
  82. <% if recent_forum_activity(forum) %>
  83. @@ -40,7 +53,7 @@
  84. <%= image_tag "clearbits/comment.gif", :class => "icon grey", :title => "No recent activity" %>
  85. <% end %>
  86. </td>
  87. - <td class="c2">
  88. + <td class="c2" <%= 'style=padding-left:'+(5+(forum.ancestors.size*15)).to_s+'px' if forum.ancestors.size > 0 -%>>
  89. <%= link_to "Edit", edit_forum_path(forum), :class => "tiny", :rel => "directory", :style => "float:right" if admin? %>
  90.  
  91. <%= link_to h(forum.name), forum_path(forum), :class => "title" %>
  92. @@ -63,6 +76,7 @@
  93. <span>(<%= link_to 'view', topic_path(:forum_id => forum, :id => forum.posts.last.topic_id, :page => forum.posts.last.topic.last_page, :anchor => forum.posts.last.dom_id) %>)</span>
  94. <% end %>
  95. </td>
  96. + <% end -%>
  97. </tr>
  98. <% end %>
  99. </table>
Add Comment
Please, Sign In to add comment