daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Feb 19th, 2018 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 %>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top