Guest User

Untitled

a guest
Feb 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. ## Goal [plaintext]
  2. <option>Root category</option>
  3. <option> Sub category 1</option>
  4. <option> Sub category 2</option>
  5. <option> Sub-sub category</option>
  6. <option selected="selected"> Selected category</option
  7.  
  8. ## Current code (ugly) [ruby]
  9. <%
  10.  
  11. def render_category(category)
  12. code = ""
  13.  
  14. category.categories.each do |c|
  15. code += render_category c
  16. end
  17.  
  18. code += "<option"
  19.  
  20. if category.id == @chart.category_id
  21. code += " selected=\"selected\""
  22. end
  23.  
  24. code += ">"
  25. code += h(category.title)
  26. code += "</option>"
  27. end
  28.  
  29. Category.find(:all, :conditions => ["category_id IS NULL"]).each do |c|
  30. %>
  31. <%= render_category c %>
  32. <% end %>
Add Comment
Please, Sign In to add comment