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 @@
<%= f.text_field :name, size: 40, required: true %>
- <%= f.number_field :ref_amount, size: 8, required: true, min: 0 %> + <%= f.number_field :ref_amount, size: 8, required: true, min: 0, label: :field_reference %> <%= f.select :ref_unit_id, unit_options, {label: '', required: true} %>
<%= f.select :group, group_options, required: true %>
diff --git a/app/views/ingredients/index.html.erb b/app/views/ingredients/index.html.erb index dfd29a9..1a966da 100644 --- a/app/views/ingredients/index.html.erb +++ b/app/views/ingredients/index.html.erb @@ -46,7 +46,7 @@<%= i.name %> | <%= i.ref_amount %> [<%= i.ref_unit.shortname %>] | diff --git a/app/views/quantities/index.html.erb b/app/views/quantities/index.html.erb index a330a2e..f56f508 100644 --- a/app/views/quantities/index.html.erb +++ b/app/views/quantities/index.html.erb @@ -23,7 +23,7 @@
<%= q.name %> | diff --git a/app/views/units/index.html.erb b/app/views/units/index.html.erb index 01c25b5..f8d7aa2 100644 --- a/app/views/units/index.html.erb +++ b/app/views/units/index.html.erb @@ -23,7 +23,7 @@
<%= u.shortname %> | <%= u.name %> | diff --git a/config/locales/en.yml b/config/locales/en.yml index 8b20f37..c167a66 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -29,6 +29,7 @@ en: heading_common: 'Common' link_summary: 'Summary' link_ingredients: 'Ingredients' + link_sources: 'Data sources' link_quantities: 'Quantities' link_units: 'Units' link_defaults: 'Load defaults'