From 628578cda5d0f3bbe8fc799fe330a3d681b15b34 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Wed, 27 Nov 2019 22:43:58 +0100 Subject: [PATCH] Scoped all controllers inside body_trackers Fixed main menu item highlighting --- app/controllers/body_trackers_controller.rb | 2 + app/controllers/ingredients_controller.rb | 2 + app/controllers/measurements_controller.rb | 2 + app/controllers/quantities_controller.rb | 2 + app/controllers/sources_controller.rb | 2 + app/controllers/units_controller.rb | 2 + config/routes.rb | 52 ++++++++++----------- 7 files changed, 38 insertions(+), 26 deletions(-) diff --git a/app/controllers/body_trackers_controller.rb b/app/controllers/body_trackers_controller.rb index 55d4ffc..97a40ad 100644 --- a/app/controllers/body_trackers_controller.rb +++ b/app/controllers/body_trackers_controller.rb @@ -1,4 +1,6 @@ class BodyTrackersController < ApplicationController + menu_item :body_trackers + before_action :find_project_by_project_id, only: [:index, :defaults] before_action :authorize diff --git a/app/controllers/ingredients_controller.rb b/app/controllers/ingredients_controller.rb index 3e02008..86c5f13 100644 --- a/app/controllers/ingredients_controller.rb +++ b/app/controllers/ingredients_controller.rb @@ -1,6 +1,8 @@ class IngredientsController < ApplicationController require 'csv' + menu_item :body_trackers + before_action :init_session_filters before_action :find_project_by_project_id, only: [:index, :nutrients, :create, :import, :filter, :filter_nutrients] diff --git a/app/controllers/measurements_controller.rb b/app/controllers/measurements_controller.rb index cebd91b..afff1c2 100644 --- a/app/controllers/measurements_controller.rb +++ b/app/controllers/measurements_controller.rb @@ -1,4 +1,6 @@ class MeasurementsController < ApplicationController + menu_item :body_trackers + before_action :find_project_by_project_id, only: [:index, :create] before_action :find_measurement, only: [:destroy, :toggle] before_action :authorize diff --git a/app/controllers/quantities_controller.rb b/app/controllers/quantities_controller.rb index f6d267e..424a2ba 100644 --- a/app/controllers/quantities_controller.rb +++ b/app/controllers/quantities_controller.rb @@ -1,4 +1,6 @@ class QuantitiesController < ApplicationController + menu_item :body_trackers + before_action :init_session_filters before_action :find_project_by_project_id, only: [:index, :parents, :create, :filter] before_action :find_quantity, only: [:edit, :update, :destroy, :toggle, :move] diff --git a/app/controllers/sources_controller.rb b/app/controllers/sources_controller.rb index a1cf616..be04304 100644 --- a/app/controllers/sources_controller.rb +++ b/app/controllers/sources_controller.rb @@ -1,4 +1,6 @@ class SourcesController < ApplicationController + menu_item :body_trackers + before_action :find_project_by_project_id, only: [:index, :create] before_action :find_source, only: [:destroy] before_action :authorize diff --git a/app/controllers/units_controller.rb b/app/controllers/units_controller.rb index c660e74..11ef164 100644 --- a/app/controllers/units_controller.rb +++ b/app/controllers/units_controller.rb @@ -1,4 +1,6 @@ class UnitsController < ApplicationController + menu_item :body_trackers + before_action :find_project_by_project_id, only: [:index, :create] before_action :find_unit, only: [:destroy] before_action :authorize diff --git a/config/routes.rb b/config/routes.rb index 12f2f3f..7d84802 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,35 +1,35 @@ # Plugin's routes # See: http://guides.rubyonrails.org/routing.html -resources :projects do - shallow do - resources :body_trackers, only: [:index] do - post 'defaults', on: :collection - end - resources :measurements, only: [:index, :create, :destroy] do - post 'toggle', on: :member - end - resources :ingredients, only: [:index, :create, :destroy] do - post 'toggle', on: :member - collection do - get 'nutrients' - get 'filter' - get 'filter_nutrients' - post 'toggle_nutrient_column' - post 'import' +resources :projects, shallow: true do + resources :body_trackers, only: [:index] do + collection do + post 'defaults' + resources :measurements, only: [:index, :create, :destroy] do + post 'toggle', on: :member end - end - resources :sources, only: [:index, :create, :destroy] - resources :quantities, only: [:index, :create, :edit, :update, :destroy] do - member do - post 'toggle' - post 'move/:direction', to: 'quantities#move', as: :move + resources :ingredients, only: [:index, :create, :destroy] do + post 'toggle', on: :member + collection do + get 'nutrients' + get 'filter' + get 'filter_nutrients' + post 'toggle_nutrient_column' + post 'import' + end end - collection do - get 'parents' - get 'filter' + resources :sources, only: [:index, :create, :destroy] + resources :quantities, only: [:index, :create, :edit, :update, :destroy] do + member do + post 'toggle' + post 'move/:direction', to: 'quantities#move', as: :move + end + collection do + get 'parents' + get 'filter' + end end + resources :units, only: [:index, :create, :destroy] end - resources :units, only: [:index, :create, :destroy] end end