Featured post
ruby on rails - Ordering category select menu alphabetically with awesome_nested_set -
using awesome_nested_set rails 3, i've created hierarchical categories system. display category selector in view, i've used following code:
<%= form.select :parent_id, options_for_select(nested_set_options(category, @category) {|i| "#{'-' * i.level} #{i.name}" }.unshift(["no parent", nil]), @category.parent_id) %>
i'm attempting order categories in alphabetical order, on level level basis. if change nested_set_options(category, @category)
nested_set_options(category.order("name"), @category)
reorder whole categories list name; want reorder children of each node alphabetically name.
for example, want resulting select menu ordered this:
animal - bird -- chicken -- hawk - fish -- cod -- goldfish -- trout - mammal -- cat -- primate --- chimpanzee --- human -- zebra plant - tree
although unfamiliar awesome_nested_set, can call order twice in rails 3.
category.order(:level).order(:name)
this should order category each level , name within each level. also, can throw on default scope within model.
class category < activerecord::base default_scope order('level, name') ... end
orders great default scope because don't effect default values.
- Get link
- X
- Other Apps
Comments
Post a Comment