diff --git a/app/controllers/diary_entries_controller.rb b/app/controllers/diary_entries_controller.rb
index a251642..5458c99 100644
--- a/app/controllers/diary_entries_controller.rb
+++ b/app/controllers/diary_entries_controller.rb
@@ -1,5 +1,5 @@
class DiaryEntriesController < ApplicationController
- before_action :set_diary_entry, only: [:show, :edit, :update, :destroy]
+ before_action :set_diary_entry, only: [:show, :edit, :update]
def index
@diary_entries = DiaryEntry.all
@@ -50,6 +50,7 @@ class DiaryEntriesController < ApplicationController
:work_stress_level,
:life_stress_level,
:sleep_quality_level,
+ :weight,
)
end
end
diff --git a/app/models/diary_entry.rb b/app/models/diary_entry.rb
index f0f7ae0..fff77ca 100644
--- a/app/models/diary_entry.rb
+++ b/app/models/diary_entry.rb
@@ -9,5 +9,16 @@ class DiaryEntry < ApplicationRecord
:work_stress_level,
:life_stress_level,
:sleep_quality_level,
+ :weight,
presence: true
+
+ validates :pain_level,
+ :energy_level,
+ :mental_alertness_level,
+ :work_stress_level,
+ :life_stress_level,
+ :sleep_quality_level,
+ numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 10 }
+
+ validates :weight, numericality: { greater_than_or_equal_to: 0 }
end
diff --git a/app/views/diary_entries/_form.html.erb b/app/views/diary_entries/_form.html.erb
index 44d6136..dae85b2 100644
--- a/app/views/diary_entries/_form.html.erb
+++ b/app/views/diary_entries/_form.html.erb
@@ -22,6 +22,9 @@
<%= f.label :sleep_quality_level %>
<%= f.number_field :sleep_quality_level %>
+ <%= f.label :weight %>
+ <%= f.number_field :weight %>
+
<%= f.label :notes %>
<%= f.text_area :notes %>
diff --git a/app/views/diary_entries/_levels.html.erb b/app/views/diary_entries/_levels.html.erb
index 82d0640..1283820 100644
--- a/app/views/diary_entries/_levels.html.erb
+++ b/app/views/diary_entries/_levels.html.erb
@@ -7,6 +7,7 @@
<%= t(".work_stress_level") %> |
<%= t(".life_stress_level") %> |
<%= t(".sleep_quality_level") %> |
+ <%= t(".weight") %> |
@@ -17,6 +18,7 @@
<%= diary_entry.work_stress_level %> |
<%= diary_entry.life_stress_level %> |
<%= diary_entry.sleep_quality_level %> |
+ <%= diary_entry.weight %> |
diff --git a/config/locales/views/diary_entries/en.yml b/config/locales/views/diary_entries/en.yml
index 2644b7a..b141402 100644
--- a/config/locales/views/diary_entries/en.yml
+++ b/config/locales/views/diary_entries/en.yml
@@ -23,3 +23,4 @@ en:
work_stress_level: Work Stress
life_stress_level: Life Stress
sleep_quality_level: Sleep Quality
+ weight: Weight
diff --git a/db/migrate/20231231112357_add_weight_to_diary_entry.rb b/db/migrate/20231231112357_add_weight_to_diary_entry.rb
new file mode 100644
index 0000000..bf124d2
--- /dev/null
+++ b/db/migrate/20231231112357_add_weight_to_diary_entry.rb
@@ -0,0 +1,5 @@
+class AddWeightToDiaryEntry < ActiveRecord::Migration[7.1]
+ def change
+ add_column :diary_entries, :weight, :float
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index ade4abf..3978ac6 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.1].define(version: 2023_12_29_143820) do
+ActiveRecord::Schema[7.1].define(version: 2023_12_31_112357) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -75,6 +75,7 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_29_143820) do
t.integer "sleep_quality_level", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
+ t.float "weight"
t.index ["user_id"], name: "index_diary_entries_on_user_id"
end
diff --git a/test/fixtures/diary_entries.yml b/test/fixtures/diary_entries.yml
index 59e368d..af86e63 100644
--- a/test/fixtures/diary_entries.yml
+++ b/test/fixtures/diary_entries.yml
@@ -8,6 +8,7 @@ one:
work_stress_level: 10
life_stress_level: 10
sleep_quality_level: 10
+ weight: 86
two:
user: trevor
@@ -19,3 +20,4 @@ two:
work_stress_level: 1
life_stress_level: 1
sleep_quality_level: 10
+ weight: 89