diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2017-02-09 01:57:46 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2017-02-09 01:57:46 +0300 |
commit | a6a3df644e39554097bc30b017005d89431336e6 (patch) | |
tree | 786d416a7e6f04d1182c106af0cf1b653f910fe5 /app | |
parent | b28d66c38d95e779157e9f68f68e7ca3b0ba2521 (diff) | |
parent | 4d40c3c30a945d28487dfe08c0985ccb636ce3bc (diff) |
Merge branch 'dz-fix-route-rename-descendants' into 'master'
Fix route rename descendants if route.name is blank
See merge request !9074
Diffstat (limited to 'app')
-rw-r--r-- | app/models/route.rb | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/app/models/route.rb b/app/models/route.rb index 4eec3e73d5b..73574a6206b 100644 --- a/app/models/route.rb +++ b/app/models/route.rb @@ -15,14 +15,19 @@ class Route < ActiveRecord::Base descendants = Route.where('path LIKE ?', "#{path_was}/%") descendants.each do |route| - attributes = { - path: route.path.sub(path_was, path), - name: route.name.sub(name_was, name) - } + attributes = {} + + if path_changed? && route.path.present? + attributes[:path] = route.path.sub(path_was, path) + end + + if name_changed? && route.name.present? + attributes[:name] = route.name.sub(name_was, name) + end # Note that update_columns skips validation and callbacks. # We need this to avoid recursive call of rename_descendants method - route.update_columns(attributes) + route.update_columns(attributes) unless attributes.empty? end end end |