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..30c585c 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 @@ -11,4 +11,4 @@ class Food < ApplicationRecord def name_with_measurement_unit "#{name} (#{measurement_unit})" end -end \ No newline at end of file +end 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' %>