Skip to content

Commit

Permalink
Fix menuitems ordering #2
Browse files Browse the repository at this point in the history
  • Loading branch information
gordienko committed Aug 13, 2022
1 parent 6f5e895 commit fbea56e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
11 changes: 1 addition & 10 deletions app/controllers/menuitems_controller.rb
Expand Up @@ -59,16 +59,7 @@ def destroy

def move
@menuitem = Menuitem.find(params[:id])
if params[:ancestry] == 'undefined'
@menuitem.update_columns(ancestry: nil)
else
@menuitem.update_columns(ancestry: params[:ancestry])
end

@menuitem.siblings.order(:position).each.with_index(1) do |item, index|
item.update_column(:position, index)
end

@menuitem.update(parent_id: params[:ancestry] == 'undefined' ? nil : params[:ancestry])
@menuitem.insert_at(params[:position].to_i)
head :ok
end
Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
@@ -1 +1 @@
1000.times { |n| Menuitem.create!(name: "Menu title number #{n}") }
20.times { |n| Menuitem.create!(name: "Menu title number #{n}") }

0 comments on commit fbea56e

Please sign in to comment.