Code Monkey home page Code Monkey logo

the_sortable_tree's Introduction

TheSortableTree

Gem Version Code Climate

tested with rails 4.1.0rc2 + haml 4

Nested Set + Drag&Drop GUI. Very fast! Best render helper! 2000 nodes/sec. Ready for rails 4 (RubyGems)

Dummy Application

Sortable tree. Drag&Drop GUI

Drag&Drop GUI. Sotrable tree

Render tree

Render tree

Render Nested Options

Nested options

Expandable tree

Expandable

Keywords

Awesome nested set, Nested set, Ruby, Rails, Nested set view helper, Sortable nested set, Drag&Drop GUI for nested set, View helper for nested set, render tree

Install

Gemfile (Rails 3, Rails 4)

gem 'awesome_nested_set' # or any similar gem (gem 'nested_set')
gem "the_sortable_tree", "~> 2.5.0"

Console

bundle

Using

JQuery and JavaScripts

app/assets/javascripts/application.js

Sortable GUI require JQuery libs

//= require jquery
//= require jquery-ui
//= require jquery_ujs

Add next JS only for Sortable GUI

//= require the_sortable_tree/jquery.ui.nestedSortable
//= require the_sortable_tree/sortable_ui/base

// with Turbolinks
$ ->
  TheSortableTree.SortableUI.init()

// with Turbolinks
$(document).on "ready page:load", ->
  TheSortableTree.SortableUI.init()

Stylesheets

app/assets/stylesheets/application.css

*= require tree
*= require sortable_tree
*= require nested_options

*= the_sortable_tree/sortable_ui/base
  ol.the-sortable-tree.the-sortable-tree--list(data={ max_levels: 5, rebuild_url: rebuild_hubs_url })
    = sortable_tree @hubs

Extend your Routes for Sortable GUI

resources :pages do
  collection do
    get :manage

    # required for Sortable GUI server side actions
    post :rebuild
  end
end

manage - just page, where you want render Sortable tree.

Extend your Model

class Page < ActiveRecord::Base
  acts_as_nested_set scope: :user
  include ::TheSortableTree::Scopes

  # any code here
end

Extend your controller and find your tree

class PagesController < ApplicationController
  include ::TheSortableTreeController::Rebuild

  def manage
    @pages = Page.nested_set.select('id, title, content, parent_id').all
  end

  # any code here
end

Basic Render Method

build_server_tree(tree, options)

Render Tree

app/views/pages/manage.html.haml

%ol.tree= just_tree @pages

just_tree is just alias of build_server_tree(tree, type: :tree)

Render Sortable Tree

%ol.sortable_tree{ data: { max_levels: 5, rebuild_url: rebuild_pages_url } }
  = sortable_tree @pages

sortable_tree is just alias of build_server_tree(tree, type: :sortable)

Render Nested Options Tree

= select_tag :page_id, nested_options(@pages, :selected => Page.last), class: :nested_options

nested_options is just alias of build_server_tree(tree, type: :nested_options)

build_server_tree options

Client side:

Required params for sortable GUI! Must be defined at root element of tree.

  1. max_levels - maximum depth of nesting
  2. rebuild_url - URL to rebuild method on server side
%ol.sortable_tree{ data: { max_levels: 3, rebuild_url: rebuild_pages_url } }

Server side:

define

build_server_tree(pages, {:option_1 => :value_1, :option_2 => :value_2})

use

options[:NAME]

Options list:

  1. id - id field of node
  2. title - title field of node
  3. type - type of tree [tree|sortable|nested_options]
  4. namespace - for example: :admin. [] - by default
  5. render_module - your own Render Tree Helper

Rendering runtime params (see code of render helpers):

You can use next options, when rendering run:

  1. level - level number
  2. root - root flag [true|false]
  3. klass - class name
  4. has_children - has children flag [true|false]
  5. children - array of children

Customization

Try to run next view generators:

Render helpers for HTML tree generation

bundle exec rails g the_sortable_tree:views tree
bundle exec rails g the_sortable_tree:views sortable
bundle exec rails g the_sortable_tree:views nested_options

Base Render helper of gem

bundle exec rails g the_sortable_tree:views helper

Assets of gem

bundle exec rails g the_sortable_tree:views assets

I want to know more

  1. How to change HTML code of tree?
  2. How to create new tree HTML Builder helper?
  3. I need to render reversed tree
  4. Gem can't correctly define a Name of your Model
  5. ChangeLog

Is it fast? Yes, it is!

BANCHMARK:

tree params: 16.000 nodes, 3 levels

  • Views: 7999.6ms | ActiveRecord: 79.2ms
  • WebInspector full time ~ 9.64s

total: ~ 2000 nodes/sec

Looking for maintainers

Do you want to be open source contributor? There are some ideas:

Try to create view helpers for:

  1. Mongoid NestedSet
  2. acts_as_ordered_tree
  3. Expand tree via AJAX
  4. Comments Tree gem
  5. gem Ancestry (???)

I want to try! I need tests!

  1. I'm develop gem with test app the_sortable_tree_test_app. You can clone it and see some testcase-pages for gem
  2. Sorry, but I have not tests for this gem. Gem is so simple. It's easy to test only with test app.
  3. You can write some tests, if your need. I will be happy certainly.
  4. No! I know RSpec. I can write tests. But I have not reasons to write tests here.

Аcknowledgment

  1. mjsarfatti/nestedSortable
  2. iconza

this line fot testing with submodules

The MIT License (MIT)

Copyright 2009-2013 Ilya N. Zykin (the-teacher), Mikhail Dieterle (Mik-die), Matthew Clark

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

the_sortable_tree's People

Contributors

anhtrantuan avatar aypn0s avatar gbrain avatar joshuatatterton avatar juanortizthirdwave avatar mariuz avatar mikdiet avatar rhizome avatar taimoor avatar taimoorchangaiz avatar tallica avatar tanraya avatar the-teacher avatar vadimstroganov avatar vincenzor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

the_sortable_tree's Issues

Expandable or sortable tree with custom title field

Hi, sorry to bother you with such question but how do you render a tree with a custom title field.... Let's says I want my Model field "name" to be the title of the nodes.

I tried many variations of:

%ol.sortable_tree.expandable{ data: {rebuild_url: rebuild_type_articles_url, expand_node_url: expand_node_type_articles_url } }
= expandable_tree @type_article, :title => :name

but each time I end up with a "undefined method `title' for #TypeArticle:0x000000058abce0" error.
Any help would be welcomed.
Thanks by advance.

Add possibility to have sortable_tree view be closed and opened

For a project it would be great to have the sortable tree be closed and opened.

We implemented it with a little hack but now we need to change the jquery UI nested sortable file. You know this is not good, so I am wondering if the functionality could be added to the_sortable_tree

Solving slowness

If you use a nested set make use of the possibility to fetch the whole tree in one query.
I saw you used the #children method to recursively fetch the whole tree, but fetching it using one #each_with_level call is much faster :)

ajax capable tree

hi,

wouldn't it be better to go with an ajax-capable js plugin?
http://www.jstree.com/
and implement it as ajax only (incremental)
i m not so sure if it s a good idea to load the complete tree.
we got performance problems for a big customer which had a lot of nodes.

Rebuild action not sync the client and server

when we by droping a node under another node in a tree, rebuild action gets called which save the position and render nothing and status ok.
This works fine as by droping of node it shown correcty on client and in rebuild it save the tree structure in database.
But if something breaks in rebuild action that is not notified to end user or drop is reverted.

So the tree structure on client and on server are not in sync

Working with engines

I think the 'klass =' line does not work properly here:
module TheSortableTreeController
...
module DefineVariablesMethod
public
def the_define_common_variables
...
--->> klass = self.respond_to?(:sortable_model) ? self.sortable_model : variable.classify.constantize # Recipe <<---

I have the 'Swxtodo::Todo' model class in my engine and this gives me only Todo. However I need Swxtodo::Todo. Changing to klass = self.class.to_s.sub(/Controller/,'').classify.constantize works for me, but I don't understand the respond_to part. Can you please fix the original code to work with engine's models as Swxtodo::Todo?
Thank you!

The sortable tree 1.5.0 doesn't work with rails 3.2

When I add sortable tree v1.5.0 to my Gemfile I get the following error:

Bundler could not find compatible versions for gem "rails":
  In Gemfile:
    the_sortable_tree (~> 1.5.0) ruby depends on
      rails (~> 3.1.0) ruby

    rails (3.2.1)

It depends on Rails 3.1.0.

When I add sortable tree without a specific version number to the Gemfile I get v1.4.8, which does work properly.

drag drop hook

I want to do something after user drag/drop , is there any hooks I can use ?

thanks

Parameters are blank?

My code looks like this:

%ol.sortable_tree{ data: { max_levels: 3, rebuild_url: rebuild_articles_url } }
  = sortable_tree @articles

Then I have a nice list with li elements with id="31_article" (31 as example).

When I sort it seems to work, but when I refresh it doesn't. It appears that the parameters [:next_id, :prev_id] are empty:

Started POST "/articles/rebuild" for 127.0.0.1 at 2013-09-11 16:34:45 +0200
Processing by ArticlesController#rebuild as JS
  Parameters: {"prev_id"=>"", "next_id"=>""}

Any idea why?

change the updated_at field

When I call the rebuild or move* methods the updated_at field is unchanged. It is not good because I watch the updated_at field to expire my cache.

ERB alternatives

Hello,

I'm using ERB but I can't really figure out how to convert the HAML code to something in ERB. I tried some stuff but it seems my rebuild path is used incorrectly. When I'm using the HAML code (the tree is a HAML partial, ugly as hell) it works.

So what is the erb alternative? (Maybe this should be added to the documentation)

Thanks!

sql error

Hello,

I followed the read me, but i have this error :
SQLite3::SQLException: no such column: lft: SELECT id, nom, parent_id FROM "menus" ORDER BY lft ASC

I use rails 3.2, did i miss something ?

Thanks for your help.

Confirm when drop

I'm beginner with js so I want to show confirm dialog after drop item, if confirm ok => update tree else do nothing.
Please help me, thanks so much!

Error msg during installation: 'The validation message from Rubygems was: ["MIT-LICENSE"] are not files'

Gemfile:

gem 'awesome_nested_set'
gem 'the_sortable_tree', :git => "https://github.com/the-teacher/the_sortable_tree"
Using the_sortable_tree (1.9.4) from https://github.com/the-teacher/the_sortable_tree (at master) 
the_sortable_tree at /home/alexvs/.rvm/gems/ruby-1.9.3-p194@rails3tutorial2ndEd/bundler/gems/the_sortable_tree-100f939cd46d did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
  ["MIT-LICENSE"] are not files

Render sub tree by ajax

Hello.
Thanks for this good gem.

So lets go to the answer.
I have tree over than 5000 elements with many levels.
By default this gem renders all tree. Its not good in this case, 'cause slow.
And I did rendering by ajax next level when click on node.

I think it can be good if rendering by ajax will be part of gem.
Like

 sortable_tree ..., :ajax => true

If you interested I try to make pull request with this feature.

Rebuild of sortable tree with namespace not working

I do have a sortable tree set with in Admin namespace:

  def manage
    @pages = Admin::Page.nested_set.select('id, title, text, parent_id').all
  end
%ol.sortable_tree{ data: { max_levels: 5, rebuild_url: rebuild_admin_pages_url } }
  = build_server_tree @pages, :type => :sortable, :namespace => :admin

trace:

undefined method `admin_admin_page_path' for #<#<Class:0x007f8dc90e3068>:0x007f8dc90dff08>
Extracted source (around line #2):

1: %ol.sortable_tree{ data: { max_levels: 5, rebuild_url: rebuild_admin_pages_url } }
2:   = build_server_tree @pages, :type => :sortable, :namespace => :admin

It looks like it adds namespace to path twice.
Or is it just my error? I've tried your test app but this thing in admin namespace is not working either.

May require jQuery Turbolinks

Found strange bug. My menu editing interface has address /admin/menus, it contains both editing form and 2 level sortable tree list. The editing form ends with Cancel/Save buttons like so:

<a class="btn btn-default" href="/admin/menus">Cancel</a> or <input class="btn btn-primary" name="commit" type="submit" value="Save" />

First time I visit this page, everythig looks fine, sortable tree drag&drop works like charm. But after I press Cancel, which leads me to the same URL where I just came from, nothing happens -- drag&drop is now broken until I press refresh or POST with Save.

After I installed https://github.com/kossnocorp/jquery.turbolinks the issue was gone, so I guess there's something related to the turbolink's javascript innitialization code.

gem "rails", "4.1"
gem "awesome_nested_set", "> 3.0.0.rc.5"
gem "the_sortable_tree", "
> 2.5.0"
gem "jquery-rails"
gem "jquery-ui-sass-rails"

Doesnot work with nested resource

I have a resource pages which is nested in hotels. Pages can have a hierarchical structure. So I tried to use this gem but in vain...

Error log:

ActionView::Template::Error (undefined method page_path' for #<#<Class:0xb3413e4>:0xb3392c0>): 1: <%- 2: title = node.send opts[:title] 3: handle = content_tag :i, '', :class => :handle 4: link = link_to(title, url_for(node), :title => title) 5: controls = render(:partial => "#{opts[:path]}/controls", :locals => { :node => node, :opts => opts }) 6: controls = content_tag(:b, controls, :class => :controls) 7: element = handle + controls + link app/views/pages/the_sortable_tree/_link.html.erb:4:in_app_views_pages_the_sortable_tree__link_html_erb___471767226_94107150'
app/views/pages/the_sortable_tree/_node.html.erb:2:in block in _app_views_pages_the_sortable_tree__node_html_erb___956115697_94154110' app/views/pages/the_sortable_tree/_node.html.erb:1:in_app_views_pages_the_sortable_tree__node_html_erb___956115697_94154110'
app/views/pages/index.html.erb:31:in `_app_views_pages_index_html_erb__217089846_95196580'

Rails 4

I dont believe this is ready for rails 4. It looks like its generating non-digest assets within the CSS so the sort images are not rendering.

Do you know of a fix for this?

Using the_sortable_tree in mountable engine

У меня есть mountable engine в котором используется the_sortable_tree.
В engine название модели содержит неймспейс, например MenuWithPages::MenuItem.
Похоже, поэтому и возникает ошибка при использовании в engine.

(uninitialized constant MenuItem): .... activesupport (3.2.8) lib/active_support/core_ext/string/inflections.rb:54:inconstantize'
the_sortable_tree-668ccbac99c3/app/controllers/the_sortable_tree_controller.rb:10:in the_define_common_variables' the_sortable_tree-668ccbac99c3/app/controllers/the_sortable_tree_controller.rb:34:inrebuild'
....
`

В пулл ревквесте прилагаю вариант решения проблемы.

undefined method `render_tree'

Can you help me? I got such error:

Started GET "/categories" for 127.0.0.1 at 2012-11-18 17:36:19 +0200
Processing by CategoriesController#index as HTML
  Sessions Load (3.1ms)  SELECT "sessions".* FROM "sessions" WHERE "sessions"."sid" = 'exSx9u0Qg7bJ7Zkh6GI1DA' LIMIT 1
  User Load (5.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
  CACHE (0.0ms)  SELECT "sessions".* FROM "sessions" WHERE "sessions"."sid" = 'exSx9u0Qg7bJ7Zkh6GI1DA' LIMIT 1
  Category Load (0.8ms)  SELECT "categories".* FROM "categories" WHERE "categories"."user_id" = 1
  Rendered categories/index.html.erb within layouts/application (12.7ms)
Completed 500 Internal Server Error in 238ms

ActionView::Template::Error (undefined method `render_tree' for #<#<Class:0xb399dab4>:0xb399c150>):
    1: <div class="span8">
    2:   <%= render_tree(@categories, type: :sortable) %>
    3: 
  app/views/categories/index.html.erb:2:in `_app_views_categories_index_html_erb___882395088_97286600'
  app/controllers/categories_controller.rb:15:in `index'

Gemfile

gem 'awesome_nested_set'
gem 'the_sortable_tree'

routes.rb

  resources :categories do
    collection do
      get  :manage
      post :rebuild
    end
  end

models/category.rb

# == Schema Information
#
# Table name: categories
#
#  id        :integer          not null, primary key
#  name      :string(255)      not null
#  user_id   :integer          not null
#  parent_id :integer
#  lft       :integer
#  rgt       :integer
#  depth     :integer
#

class Category < ActiveRecord::Base
  include TheSortableTree::Scopes

  acts_as_nested_set
  attr_accessible :name, :parent_id

  has_many :transaction

  belongs_to :user
  validates :user_id, :presence => true
end

controllers/categories_controller.rb

class CategoriesController < ApplicationController
  include TheSortableTreeController::Rebuild

  before_filter :loged_in
  respond_to :json, :html

  def manage
    # IMPORTANT! Select only required fields
    @categories = current_user.category.nested_set.select('id, name, parent_id').all
  end

  def index
    @categories = current_user.category.all

    respond_with(@categories)
  end
end

views/categories/index.html.erb

<div class="span8">
  <%= render_tree(@categories, type: :sortable) %>
</div>

NoMethodError when tree in build_server_tree is nil

When you call i.e.

= build_server_tree @categories, type: :sortable, namespace: :admin

and @categories is nil, NoMethodError raised.

roots = opts[:boost][0] is nil.

roots.each do |root| _opts = opts.merge({ :node => root, :root => true, :level => opts[:level].next, :boost => opts[:boost] }) result << build_server_tree(tree, _opts) end

drag & drog multi nodes

can the plugin support the feature ?

if it can't , can you tell me how to do it , I can make my branch .

Typo in expand_node function

There is typo in the_sortable_tree_controller.rb in expand_node function. There is

"return render(nothing: :true)" instead of "return render(nothing: true)"

Add info for expandable tree to README

Hello, in the README there is no info about using the expandable tree formatter.

Is this the only format that supports having a new_url, which I assume is for adding new entries on the sorting page?

Thanks in advance

Возможность ограничить глубину дерева

Здравствуйте. Хотелось бы использовать Ваш gem для управления категориями публикаций в блоге.

Возможно но ли ограничить создания детей не более третьего уровня?

То есть запретить перетягивание, например элемента первого уровня с дочерним элементом на третий(так как в итоге будет глубина 4)?

Wrong rebuild url for CamelCase models

Hello,

I came across an issue and I thought I should report it. If you have a two-word model model (say ArticleCategory) the ajax rebuild url that will be generated will be 'articlecategories' when it should be 'article_categories' in order to work with the controller. The way to fix this is in the sortable tree helper and change

def define_class_of_elements_of tree
case
when tree.is_a?(ActiveRecord::Relation) then tree.name.to_s.downcase
when tree.empty? then nil
else tree.first.class.to_s.downcase
end
end

with

def define_class_of_elements_of tree
case
when tree.is_a?(ActiveRecord::Relation) then tree.name.to_s.underscore.downcase
when tree.empty? then nil
else tree.first.class.to_s.underscore.downcase
end
end

Nothing happens when changing order?

The tree renders fine. Adding new pages, deleting pages and moving pages to subtrees also works. However, sorting doesn't update anything. The output:

Started POST "/admin/pages/rebuild" for 127.0.0.1 at 2012-11-26 14:23:00 +0100
Processing by Admin::PagesController#rebuild as JS
Parameters: {"id"=>"2_page", "parent_id"=>"1_page", "prev_id"=>"16_page", "next_id"=>"12_page"}

...

SQL (0.9ms) UPDATE "pages" SET "lft" = CASE WHEN "lft" BETWEEN 5 AND 14 THEN "lft" + 23 - 14 WHEN "lft" BETWEEN 15 AND 23 THEN "lft" + 5 - 15 ELSE "lft" END, "rgt" = CASE WHEN "rgt" BETWEEN 5 AND 14 THEN "rgt" + 23 - 14 WHEN "rgt" BETWEEN 15 AND 23 THEN "rgt" + 5 - 15 ELSE "rgt" END, "parent_id" = CASE WHEN id = 2 THEN 1 ELSE "parent_id" END WHERE "pages"."id" IN (SELECT "pages"."id" FROM "pages" ORDER BY "pages"."lft")

When I execute the above query in the console I get nil as result.

I don't know what could be the cause of this? I have attr_accessible :parent_id and attr_protected :lft, :rgt in Page.

uninitialized constant TheSortableTreeController inside engine

Hi I'm writing a rails engine and added the_sortable_tree as a dependency.

My controller looks like this
module KB class AccountsController < ApplicationController include ::TheSortableTreeController::Rebuild end end
However this throws error "uninitialized constant TheSortableTreeController"

The depth column is ignored?

Hi,

What a great gem...

It seems the depth column is ignored when the models are updated.
In the DB, depth stay NULL.

Why Drag drop items in tree not working ?

I am trying to implement the manage action, but, I have a problem that I can't drag drop items in the tree, any idea please ?

here is my application.js

//= require jquery
//= require jquery_ujs
//= require jquery.ui.all
//= require cocoon
//= require jquery.ui.nestedSortable
//= require sortable/base
//= require comments/base
//= require_tree .

and here is my application.css

 *= require jquery.ui.all
 *= require_self
 *= require_tree .
 *= require tree
 *= require sortable
 *= require comments_tree

and here is my gemFile:

source 'https://rubygems.org'

gem 'rails', '3.2.6'

gem 'pg'


gem 'google-analytics-rails'
gem 'jquery-rails-cdn' #, :git => 'git://github.com/yjchen/jquery-rails-cdn.git'

gem 'easy_roles'
gem 'devise'
gem 'cancan'
gem 'routing-filter'


gem "simple_form"
gem "cocoon"
gem "jquery-rails"
gem "validate_url"
gem 'haml'

gem "on_the_spot"

group :production do
  gem 'newrelic_rpm'
  gem 'thin'

end



group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'


  gem 'uglifier', '>= 1.0.3'

  gem 'less'
  gem "jquery-ui-rails"

end


gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'

gem 'awesome_nested_set'
gem 'the_sortable_tree', '>= 1.9.3'

undefined method `page_path' for #<#<Class:0x000000032b49b0> [Nested Routes Handling Issue]

Note: It seems that new gem version is burst out with nested routes. Kindly guide me the way to get rid of it.

I've upgraded to rails 3.2.13 using your gem version 2.3.2.

I've pages controller and used nested route for it '/hotels/:hotel_id/pages/new'. It was working fine in rails 3.1.11 and your gem version 1.8.0 but now in view html.erb file it gives me error.

NoMethodError - undefined method page_path' for #<#<Class:0x000000032b49b0>:0x007f5d8c09f830>: (gem) actionpack-3.2.13/lib/action_dispatch/routing/polymorphic_routes.rb:129:inpolymorphic_url'
(gem) actionpack-3.2.13/lib/action_dispatch/routing/polymorphic_routes.rb:135:in polymorphic_path' (gem) actionpack-3.2.13/lib/action_view/helpers/url_helper.rb:111:inurl_for'
(gem) the_sortable_tree-2.3.2/app/helpers/render_sortable_tree_helper.rb:34:in show_link' (gem) the_sortable_tree-2.3.2/app/helpers/render_sortable_tree_helper.rb:23:inrender_node'
(gem) the_sortable_tree-2.3.2/app/helpers/the_sortable_tree_helper.rb:29:in build_tree_html' (gem) the_sortable_tree-2.3.2/app/helpers/the_sortable_tree_helper.rb:127:inbuild_server_tree'
(gem) the_sortable_tree-2.3.2/app/helpers/the_sortable_tree_helper.rb:123:in block in build_server_tree' (gem) the_sortable_tree-2.3.2/app/helpers/the_sortable_tree_helper.rb:121:inbuild_server_tree'
(gem) the_sortable_tree-2.3.2/app/helpers/the_sortable_tree_helper.rb:123:in block in build_server_tree' (gem) the_sortable_tree-2.3.2/app/helpers/the_sortable_tree_helper.rb:121:inbuild_server_tree'
(gem) the_sortable_tree-2.3.2/app/helpers/the_sortable_tree_helper.rb:123:in block in build_server_tree' (gem) the_sortable_tree-2.3.2/app/helpers/the_sortable_tree_helper.rb:121:inbuild_server_tree'
(gem) the_sortable_tree-2.3.2/app/helpers/the_sortable_tree_helper.rb:123:in block in build_server_tree' (gem) the_sortable_tree-2.3.2/app/helpers/the_sortable_tree_helper.rb:121:inbuild_server_tree'
(gem) the_sortable_tree-2.3.2/app/helpers/the_sortable_tree_helper.rb:111:in block in build_server_tree' (gem) the_sortable_tree-2.3.2/app/helpers/the_sortable_tree_helper.rb:109:inbuild_server_tree'
(gem) the_sortable_tree-2.3.2/app/helpers/the_sortable_tree_helper.rb:41:in sortable_tree' app/views/pages/index.html.erb:9:in_app_views_pages_index_html_erb__1838514784977886306_70019879107800'
(gem) actionpack-3.2.13/lib/action_view/template.rb:145:in block in render' (gem) activesupport-3.2.13/lib/active_support/notifications.rb:125:ininstrument'
(gem) actionpack-3.2.13/lib/action_view/template.rb:143:in render' (gem) actionpack-3.2.13/lib/action_view/renderer/template_renderer.rb:47:inblock (2 levels) in render_template'
(gem) actionpack-3.2.13/lib/action_view/renderer/abstract_renderer.rb:38:in block in instrument' (gem) activesupport-3.2.13/lib/active_support/notifications.rb:123:inblock in instrument'
(gem) activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in instrument' (gem) activesupport-3.2.13/lib/active_support/notifications.rb:123:ininstrument'
(gem) actionpack-3.2.13/lib/action_view/renderer/abstract_renderer.rb:38:in instrument' (gem) actionpack-3.2.13/lib/action_view/renderer/template_renderer.rb:46:inblock in render_template'
(gem) actionpack-3.2.13/lib/action_view/renderer/template_renderer.rb:54:in render_with_layout' (gem) actionpack-3.2.13/lib/action_view/renderer/template_renderer.rb:45:inrender_template'
(gem) actionpack-3.2.13/lib/action_view/renderer/template_renderer.rb:18:in render' (gem) actionpack-3.2.13/lib/action_view/renderer/renderer.rb:36:inrender_template'
(gem) actionpack-3.2.13/lib/action_view/renderer/renderer.rb:17:in render' (gem) actionpack-3.2.13/lib/abstract_controller/rendering.rb:110:in_render_template'
(gem) actionpack-3.2.13/lib/action_controller/metal/streaming.rb:225:in _render_template' (gem) actionpack-3.2.13/lib/abstract_controller/rendering.rb:103:inrender_to_body'
(gem) actionpack-3.2.13/lib/action_controller/metal/renderers.rb:28:in render_to_body' (gem) actionpack-3.2.13/lib/action_controller/metal/compatibility.rb:50:inrender_to_body'
(gem) actionpack-3.2.13/lib/abstract_controller/rendering.rb:88:in render' (gem) actionpack-3.2.13/lib/action_controller/metal/rendering.rb:16:inrender'
(gem) actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:40:in block (2 levels) in render' (gem) activesupport-3.2.13/lib/active_support/core_ext/benchmark.rb:5:inblock in ms'
/home/coeus/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/benchmark.rb:295:in realtime' (gem) activesupport-3.2.13/lib/active_support/core_ext/benchmark.rb:5:inms'
(gem) actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:40:in block in render' (gem) actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:83:incleanup_view_runtime'
(gem) activerecord-3.2.13/lib/active_record/railties/controller_runtime.rb:24:in cleanup_view_runtime' (gem) actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:39:inrender'
(gem) remotipart-1.0.5/lib/remotipart/render_overrides.rb:14:in render_with_remotipart' (gem) actionpack-3.2.13/lib/action_controller/metal/implicit_render.rb:10:indefault_render'
(gem) actionpack-3.2.13/lib/action_controller/metal/implicit_render.rb:5:in send_action' (gem) actionpack-3.2.13/lib/abstract_controller/base.rb:167:inprocess_action'
(gem) actionpack-3.2.13/lib/action_controller/metal/rendering.rb:10:in process_action' (gem) actionpack-3.2.13/lib/abstract_controller/callbacks.rb:18:inblock in process_action'
(gem) activesupport-3.2.13/lib/active_support/callbacks.rb:447:in _run__3561563905337554102__process_action__2161468695265538341__callbacks' (gem) activesupport-3.2.13/lib/active_support/callbacks.rb:405:in__run_callback'
(gem) activesupport-3.2.13/lib/active_support/callbacks.rb:385:in _run_process_action_callbacks' (gem) activesupport-3.2.13/lib/active_support/callbacks.rb:81:inrun_callbacks'
(gem) actionpack-3.2.13/lib/abstract_controller/callbacks.rb:17:in process_action' (gem) actionpack-3.2.13/lib/action_controller/metal/rescue.rb:29:inprocess_action'
(gem) actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:30:in block in process_action' (gem) activesupport-3.2.13/lib/active_support/notifications.rb:123:inblock in instrument'
(gem) activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in instrument' (gem) activesupport-3.2.13/lib/active_support/notifications.rb:123:ininstrument'
(gem) actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:29:in process_action' (gem) actionpack-3.2.13/lib/action_controller/metal/params_wrapper.rb:207:inprocess_action'
(gem) activerecord-3.2.13/lib/active_record/railties/controller_runtime.rb:18:in process_action' (gem) actionpack-3.2.13/lib/abstract_controller/base.rb:121:inprocess'
(gem) actionpack-3.2.13/lib/abstract_controller/rendering.rb:45:in process' (gem) actionpack-3.2.13/lib/action_controller/metal.rb:203:indispatch'
(gem) actionpack-3.2.13/lib/action_controller/metal/rack_delegation.rb:14:in dispatch' (gem) actionpack-3.2.13/lib/action_controller/metal.rb:246:inblock in action'
(gem) actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:73:in dispatch' (gem) actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:36:incall'
(gem) journey-1.0.4/lib/journey/router.rb:68:in block in call' (gem) journey-1.0.4/lib/journey/router.rb:56:incall'
(gem) actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:612:in call' (gem) omniauth-1.1.4/lib/omniauth/strategy.rb:184:incall!'
(gem) omniauth-1.1.4/lib/omniauth/strategy.rb:164:in call' (gem) omniauth-1.1.4/lib/omniauth/strategy.rb:184:incall!'
(gem) omniauth-1.1.4/lib/omniauth/strategy.rb:164:in call' (gem) warden-1.2.1/lib/warden/manager.rb:35:inblock in call'
(gem) warden-1.2.1/lib/warden/manager.rb:34:in call' (gem) actionpack-3.2.13/lib/action_dispatch/middleware/best_standards_support.rb:17:incall'
(gem) rack-1.4.5/lib/rack/etag.rb:23:in call' (gem) rack-1.4.5/lib/rack/conditionalget.rb:25:incall'
(gem) actionpack-3.2.13/lib/action_dispatch/middleware/head.rb:14:in call' (gem) remotipart-1.0.5/lib/remotipart/middleware.rb:30:incall'
(gem) actionpack-3.2.13/lib/action_dispatch/middleware/params_parser.rb:21:in call' (gem) actionpack-3.2.13/lib/action_dispatch/middleware/flash.rb:242:incall'
(gem) rack-1.4.5/lib/rack/session/abstract/id.rb:210:in context' (gem) rack-1.4.5/lib/rack/session/abstract/id.rb:205:incall'
(gem) actionpack-3.2.13/lib/action_dispatch/middleware/cookies.rb:341:in call' (gem) activerecord-3.2.13/lib/active_record/query_cache.rb:64:incall'
(gem) activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in call' (gem) actionpack-3.2.13/lib/action_dispatch/middleware/callbacks.rb:28:inblock in call'
(gem) activesupport-3.2.13/lib/active_support/callbacks.rb:405:in _run__1903898215360380510__call__623521404916346025__callbacks' (gem) activesupport-3.2.13/lib/active_support/callbacks.rb:405:in__run_callback'
(gem) activesupport-3.2.13/lib/active_support/callbacks.rb:385:in _run_call_callbacks' (gem) activesupport-3.2.13/lib/active_support/callbacks.rb:81:inrun_callbacks'
(gem) actionpack-3.2.13/lib/action_dispatch/middleware/callbacks.rb:27:in call' (gem) actionpack-3.2.13/lib/action_dispatch/middleware/reloader.rb:65:incall'
(gem) actionpack-3.2.13/lib/action_dispatch/middleware/remote_ip.rb:31:in call' (gem) better_errors-0.8.0/lib/better_errors/middleware.rb:84:inprotected_app_call'
(gem) better_errors-0.8.0/lib/better_errors/middleware.rb:79:in better_errors_call' (gem) better_errors-0.8.0/lib/better_errors/middleware.rb:56:incall'
(gem) actionpack-3.2.13/lib/action_dispatch/middleware/debug_exceptions.rb:16:in call' (gem) actionpack-3.2.13/lib/action_dispatch/middleware/show_exceptions.rb:56:incall'
(gem) railties-3.2.13/lib/rails/rack/logger.rb:32:in call_app' (gem) railties-3.2.13/lib/rails/rack/logger.rb:16:inblock in call'
(gem) activesupport-3.2.13/lib/active_support/tagged_logging.rb:22:in tagged' (gem) railties-3.2.13/lib/rails/rack/logger.rb:16:incall'
(gem) actionpack-3.2.13/lib/action_dispatch/middleware/request_id.rb:22:in call' (gem) rack-1.4.5/lib/rack/methodoverride.rb:21:incall'
(gem) rack-1.4.5/lib/rack/runtime.rb:17:in call' (gem) activesupport-3.2.13/lib/active_support/cache/strategy/local_cache.rb:72:incall'
(gem) rack-1.4.5/lib/rack/lock.rb:15:in call' (gem) actionpack-3.2.13/lib/action_dispatch/middleware/static.rb:63:incall'
(gem) railties-3.2.13/lib/rails/engine.rb:479:in call' (gem) railties-3.2.13/lib/rails/application.rb:223:incall'
(gem) rack-1.4.5/lib/rack/content_length.rb:14:in call' (gem) railties-3.2.13/lib/rails/rack/log_tailer.rb:17:incall'
(gem) rack-1.4.5/lib/rack/handler/webrick.rb:59:in service' /home/coeus/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/webrick/httpserver.rb:138:inservice'
/home/coeus/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/webrick/httpserver.rb:94:in run' /home/coeus/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/webrick/server.rb:191:inblock in start_thread'

How to disable dragging child outsite root?

Hi,

very handy gem, works great for me - thanks!

In my application every user has a main page, which is the root for all pages for that particular user.
At the moment when I sort the tree I'm able to drag a child page of the root so it becomes sibling for the root - it's parent_id becomes nil.

I would like to prevent that. Any simple way to do it?

Thanks,
Marek

max nodes 15

hi,

i always get 15 nodes only
but i want to show the complete tree.

i havnt set any limits?

is this a bug?

Drag & Drop doesn't work

Drag & Drop in the "sortable tree" doesn't works with the suggested options:

%ol.sortable_tree{ data: { max_levels: 5, rebuild_url: rebuild_pages_url } }
  = sortable_tree @pages

The problem is that HAML copiles

%ol.sortable_tree{ data: { max_levels: 3, rebuild_url: "something" } }

to

<ol class='sortable_tree' data-max-levels='3' data-rebuild-url='something'></ol>

Based on this HTML the next 2 lines in the javascript

    rebuild_url   = sortable_tree.data('rebuild_url')
    max_levels    = sortable_tree.data('max_levels')

don't get anything, because the in the DOM the dataset contains always the camelCase version of the attributes, i.e. 'rebuildUrl' and 'maxLevels'. So I changed the 2 line to

    rebuild_url   = sortable_tree.data('rebuildUrl')
    max_levels    = sortable_tree.data('maxLevels')

and IT WORKS!!!

Please, tell me, if I'm wrong. You should update the gem.

BTW: Thanks for this gem, great work.

Tibor

Problem Rebuilding

When I try to move an element I get this error:
Uncaught TypeError: Object # has no method 'rebuild'

The error is coming from this line:

https://github.com/the-teacher/the_sortable_tree/blob/master/app/assets/javascripts/sortable/base.js.coffee#L28

I'm don't have a lot of time to dig in now. I do know that window.sortable.rebuild() exists, but it doesn't seem like rebuild is getting on the object that the above line is expecting. It may be a coffeescript scoping issue with -> vs => ?

Sort pages in different companies

We have multiple companies that have a sortable tree. However, when we sort the tree inside one company, it doesn't take into account the scope of the company, thus mixing every page and messing everything up :(

Tree rendering is causing extremely slow tests

I've had a problem with my controller tests beeing extremely slow. Only two simple tests had an average run time of 200s. I managed to track the issue to the just_tree method, which I use to render my main menu. When I removed the call to just_tree, the run time of the tests dropped from 200s to 0.4s.

The weird thing is that browsing the site isn't particularly slow, just the tests.
I'm using Test::Unit by the way.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.