diff options
| -rw-r--r-- | app/models/node.rb | 10 | ||||
| -rw-r--r-- | config/environment.rb | 4 | ||||
| -rw-r--r-- | lib/awesome_patch.rb | 17 |
3 files changed, 30 insertions, 1 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index 82183c9..e2ff973 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | class Node < ActiveRecord::Base | 1 | class Node < ActiveRecord::Base |
| 2 | acts_as_nested_set | 2 | acts_as_nested_set |
| 3 | |||
| 4 | # returns array with pages up to root excluding root | ||
| 5 | def path_to_root | ||
| 6 | parent.nil? && [slug] || parent.path_to_root.push(slug) | ||
| 7 | end | ||
| 8 | |||
| 9 | def update_unique_name | ||
| 10 | path = self.path_to_root[1..-1] | ||
| 11 | self.unique_name = path.join("/") | ||
| 12 | end | ||
| 3 | end | 13 | end |
diff --git a/config/environment.rb b/config/environment.rb index c53ab90..aad0815 100644 --- a/config/environment.rb +++ b/config/environment.rb | |||
| @@ -38,4 +38,6 @@ Rails::Initializer.run do |config| | |||
| 38 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. | 38 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. |
| 39 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] | 39 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] |
| 40 | # config.i18n.default_locale = :de | 40 | # config.i18n.default_locale = :de |
| 41 | end \ No newline at end of file | 41 | end |
| 42 | |||
| 43 | require 'awesome_patch' \ No newline at end of file | ||
diff --git a/lib/awesome_patch.rb b/lib/awesome_patch.rb new file mode 100644 index 0000000..1694ccf --- /dev/null +++ b/lib/awesome_patch.rb | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | module CollectiveIdea | ||
| 2 | module Acts #:nodoc: | ||
| 3 | module NestedSet | ||
| 4 | module InstanceMethods | ||
| 5 | alias_method :move_to_original, :move_to | ||
| 6 | |||
| 7 | def move_to target, position | ||
| 8 | move_to_original target, position | ||
| 9 | if self.class == Node | ||
| 10 | self.update_unique_name | ||
| 11 | self.save | ||
| 12 | end | ||
| 13 | end | ||
| 14 | end | ||
| 15 | end | ||
| 16 | end | ||
| 17 | end \ No newline at end of file | ||
