Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Goal [plaintext]
- <option>Root category</option>
- <option> Sub category 1</option>
- <option> Sub category 2</option>
- <option> Sub-sub category</option>
- <option selected="selected"> Selected category</option
- ## Current code (ugly) [ruby]
- <%
- def render_category(category)
- code = ""
- category.categories.each do |c|
- code += render_category c
- end
- code += "<option"
- if category.id == @chart.category_id
- code += " selected=\"selected\""
- end
- code += ">"
- code += h(category.title)
- code += "</option>"
- end
- Category.find(:all, :conditions => ["category_id IS NULL"]).each do |c|
- %>
- <%= render_category c %>
- <% end %>
Add Comment
Please, Sign In to add comment