Skip to content

Commit

Permalink
Merge pull request #28 from RileyManda/bug-fix
Browse files Browse the repository at this point in the history
Bug fix in migrations and controllers
  • Loading branch information
RileyManda authored Oct 17, 2023
2 parents 7df021f + ea3893d commit 0bc8787
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/controllers/food_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def new
end

def index
@food = Food.all
@foods = Food.all
end

def create
Expand Down
4 changes: 2 additions & 2 deletions app/models/food.rb
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -11,4 +11,4 @@ class Food < ApplicationRecord
def name_with_measurement_unit
"#{name} (#{measurement_unit})"
end
end
end
13 changes: 9 additions & 4 deletions app/views/food/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,24 @@
<th>Actions</th>
</tr>
</thead>

<tbody>
<% @food.each do |food| %>
<% if @foods.present? %>
<tbody>
<% @foods.each do |food| %>
<tr>
<td><%= food.name %></td>
<td><%= food.measurement_unit %></td>
<td><%= food.price %></td>
<td><%= food.quantity %></td>

</tr>
<% end %>
</tbody>

<% else %>
<p>No foods available.</p>
<% end %>


</table>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/views/food/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
</div>
</div>
<div class="card-body">
<%= form_for @food, url: { action: "create" } do |f| %>
<%= form_for @food, url: { action: "create" } do |f| %>

<div class="mb-3">
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
Expand Down

0 comments on commit 0bc8787

Please sign in to comment.