diff --git a/app/controllers/ingredients_controller.rb b/app/controllers/ingredients_controller.rb index 10cdc24..0dde53d 100644 --- a/app/controllers/ingredients_controller.rb +++ b/app/controllers/ingredients_controller.rb @@ -6,14 +6,15 @@ class IngredientsController < ApplicationController before_action :authorize def index - @ingredient = Ingredient.new(project: @project) + @ingredient = @project.ingredients.new # passing attr for after_initialize @ingredient.nutrients.new(ingredient: @ingredient) @ingredients = @project.ingredients.includes(:ref_unit) + @ingredients << @ingredient end def create - @ingredient = Ingredient.new(ingredient_params.update(project: @project)) + @ingredient = @project.ingredients.new(ingredient_params) if @ingredient.save flash[:notice] = 'Created new ingredient' redirect_to project_ingredients_url(@project) diff --git a/app/controllers/quantities_controller.rb b/app/controllers/quantities_controller.rb index 65e15bf..1136c76 100644 --- a/app/controllers/quantities_controller.rb +++ b/app/controllers/quantities_controller.rb @@ -4,12 +4,12 @@ class QuantitiesController < ApplicationController before_action :authorize def index - @quantity = Quantity.new + @quantity = @project.quantities.new @quantities = @project.quantities end def create - @quantity = Quantity.new(quantity_params.update(project: @project)) + @quantity = @project.quantities.new(quantity_params) if @quantity.save flash[:notice] = 'Created new quantity' redirect_to project_quantities_url(@project) diff --git a/app/controllers/sources_controller.rb b/app/controllers/sources_controller.rb index f3bfb46..4ac2739 100644 --- a/app/controllers/sources_controller.rb +++ b/app/controllers/sources_controller.rb @@ -1,6 +1,11 @@ class SourcesController < ApplicationController + before_action :find_project_by_project_id, only: [:index, :create] + before_action :find_source, only: [:destroy] + before_action :authorize def index + @source = @project.sources.new + @sources = @project.sources end def create diff --git a/app/controllers/units_controller.rb b/app/controllers/units_controller.rb index 2fcc0e9..31d3b32 100644 --- a/app/controllers/units_controller.rb +++ b/app/controllers/units_controller.rb @@ -4,12 +4,12 @@ class UnitsController < ApplicationController before_action :authorize def index - @unit = Unit.new + @unit = @project.units.new @units = @project.units end def create - @unit = Unit.new(unit_params.update(project: @project)) + @unit = @project.units.new(unit_params) if @unit.save flash[:notice] = 'Created new unit' redirect_to project_units_url(@project) diff --git a/app/views/body_trackers/_sidebar.html.erb b/app/views/body_trackers/_sidebar.html.erb index 9f50063..c81995b 100644 --- a/app/views/body_trackers/_sidebar.html.erb +++ b/app/views/body_trackers/_sidebar.html.erb @@ -10,6 +10,7 @@

<%= t ".heading_common" %>