Skip to content

Instantly share code, notes, and snippets.

@frcake
Created August 23, 2016 05:54
Show Gist options
  • Save frcake/f327375a6a5ed3e1466e507f55ebb1d5 to your computer and use it in GitHub Desktop.
Save frcake/f327375a6a5ed3e1466e507f55ebb1d5 to your computer and use it in GitHub Desktop.
<%=form_for categories_path do |f| %>
<%= f.select :parent_id, nested_set_options(Category, @category) {|i| "#{'-' * i.level} #{i.name}" } %>
<%= select_tag 'parent_id', options_for_select(nested_set_options(Category) {|i| "#{'-' * i.level} #{i.name}" } ) %>
<%end%>
class Category < ApplicationRecord
acts_as_nested_set
has_many :classifieds
end
class CategoriesController < ApplicationController
def index
@root_categories = Categories.roots
end
def show
@categories = Categories.find_by_id(params[:id]).self_and_descendants
end
end
@ArnonHongklay
Copy link

2 spacing is easy to reading :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment