From 3f27524716ffc8ab54209c0adec45eabef1af522 Mon Sep 17 00:00:00 2001 From: RileyManda Date: Tue, 17 Oct 2023 19:39:57 +0200 Subject: [PATCH 1/2] Bug fix in migrations and controllers --- app/controllers/food_controller.rb | 2 +- app/models/food.rb | 2 +- app/views/food/index.html.erb | 13 +++++++++---- app/views/food/new.html.erb | 3 ++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/controllers/food_controller.rb b/app/controllers/food_controller.rb index 980b214..79151ef 100644 --- a/app/controllers/food_controller.rb +++ b/app/controllers/food_controller.rb @@ -4,7 +4,7 @@ def new end def index - @food = Food.all + @foods = Food.all end def create diff --git a/app/models/food.rb b/app/models/food.rb index 3e62be7..4e02c67 100644 --- a/app/models/food.rb +++ b/app/models/food.rb @@ -1,5 +1,5 @@ class Food < ApplicationRecord - self.table_name = 'food' + self.table_name = 'foods' belongs_to :user, optional: true has_many :recipe_foods, dependent: :destroy diff --git a/app/views/food/index.html.erb b/app/views/food/index.html.erb index 74f82ef..90e28c2 100644 --- a/app/views/food/index.html.erb +++ b/app/views/food/index.html.erb @@ -16,19 +16,24 @@ Actions - + - <% @food.each do |food| %> + <% if @foods.present? %> + + <% @foods.each do |food| %> <%= food.name %> <%= food.measurement_unit %> <%= food.price %> <%= food.quantity %> - <% end %> - +<% else %> +

No foods available.

+<% end %> + + diff --git a/app/views/food/new.html.erb b/app/views/food/new.html.erb index 32423bd..42cedf3 100644 --- a/app/views/food/new.html.erb +++ b/app/views/food/new.html.erb @@ -6,7 +6,8 @@
- <%= form_for @food, url: { action: "create" } do |f| %> + <%= form_for @food, url: { action: "create" } do |f| %> +
<%= f.label :name %> <%= f.text_field :name, class: 'form-control' %> From ea3893d4ce8c616f944a520a94ba8f5a2b27c12c Mon Sep 17 00:00:00 2001 From: RileyManda Date: Tue, 17 Oct 2023 19:40:45 +0200 Subject: [PATCH 2/2] Linter fix --- app/models/food.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/food.rb b/app/models/food.rb index 4e02c67..30c585c 100644 --- a/app/models/food.rb +++ b/app/models/food.rb @@ -11,4 +11,4 @@ class Food < ApplicationRecord def name_with_measurement_unit "#{name} (#{measurement_unit})" end -end \ No newline at end of file +end