Class: WrapItRuby::MenuSettingsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- WrapItRuby::MenuSettingsController
- Defined in:
- app/controllers/wrap_it_ruby/menu_settings_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
9 10 11 12 |
# File 'app/controllers/wrap_it_ruby/menu_settings_controller.rb', line 9 def create ::MenuItem.create!() respond_with_tree_refresh end |
#destroy ⇒ Object
20 21 22 23 24 |
# File 'app/controllers/wrap_it_ruby/menu_settings_controller.rb', line 20 def destroy item = ::MenuItem.find(params[:id]) item.destroy! respond_with_tree_refresh end |
#index ⇒ Object
5 6 7 |
# File 'app/controllers/wrap_it_ruby/menu_settings_controller.rb', line 5 def index = ::MenuItem.roots.includes(children: :children) end |
#sort ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/wrap_it_ruby/menu_settings_controller.rb', line 26 def sort ordering = params.require(:ordering) ::MenuItem.transaction do ordering.each do |entry| item = ::MenuItem.find(entry[:id]) new_parent_id = entry[:parent_id].presence if item.parent_id.to_s != new_parent_id.to_s item.remove_from_list item.update!(parent_id: new_parent_id) end item.insert_at(entry[:position].to_i) end end respond_with_tree_refresh end |
#update ⇒ Object
14 15 16 17 18 |
# File 'app/controllers/wrap_it_ruby/menu_settings_controller.rb', line 14 def update item = ::MenuItem.find(params[:id]) item.update!() respond_with_tree_refresh end |