diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 3bdb9a4..d343635 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -2,11 +2,9 @@ class HomeController < ApplicationController allow_unauthenticated_access def index - user = User.find_by(username: request.subdomain) - if user&.public? - @mode = user.current_mood - @history = user.history - render template: "moods/index" + @user = User.find_by(username: request.subdomain) + if @user&.public? + render "moods/index" else redirect_to dashboard_path end diff --git a/app/controllers/moods_controller.rb b/app/controllers/moods_controller.rb index 8773247..abadc91 100644 --- a/app/controllers/moods_controller.rb +++ b/app/controllers/moods_controller.rb @@ -1,6 +1,5 @@ class MoodsController < ApplicationController def index - @mode = Current.user.current_mood - @history = Current.user.history + @user = Current.user end end diff --git a/app/helpers/moods_helper.rb b/app/helpers/moods_helper.rb index f676d1d..0c04021 100644 --- a/app/helpers/moods_helper.rb +++ b/app/helpers/moods_helper.rb @@ -1,6 +1,6 @@ module MoodsHelper - def mode_for(mood) - if params[:guess] == "active" + def mode_for(mood, user) + if user.guess? mood[:mode] || mood[:guess] || "unknown" else mood[:mode] || "unknown" diff --git a/app/views/moods/index.html.erb b/app/views/moods/index.html.erb index db55032..897ba16 100644 --- a/app/views/moods/index.html.erb +++ b/app/views/moods/index.html.erb @@ -2,7 +2,7 @@
- <%= image_tag(@mode + ".jpg", "data-mood-target": "image") %> + <%= image_tag(@user.current_mood + ".jpg", "data-mood-target": "image") %>
@@ -36,19 +36,19 @@
- Aujourd'hui : <%= @mode %> + Aujourd'hui : <%= @user.current_mood %>
- <% @history.each do |month| %> + <% @user.history.each do |month| %>
<%= I18n.l(month[:month], format: "%b %y").capitalize %>
<% month[:weeks].each do |week| %>
<% week.each do |mood| %> - <% mode = mode_for(mood) %> + <% mode = mode_for(mood, @user) %>
" data-mode="<%= mode %>" data-day="<%= l mood[:recorded_at].to_date %>" data-action="click->mood#updateDayInfo" title="<%= l(mood[:recorded_at].to_date) %> : <%= mode %>" class="day <%= mode %>">
<% end %>
diff --git a/db/migrate/20260226101258_add_guess_to_users.rb b/db/migrate/20260226101258_add_guess_to_users.rb new file mode 100644 index 0000000..038ae1c --- /dev/null +++ b/db/migrate/20260226101258_add_guess_to_users.rb @@ -0,0 +1,5 @@ +class AddGuessToUsers < ActiveRecord::Migration[8.0] + def change + add_column :users, :guess, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 3922a6e..db0c294 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[8.0].define(version: 2026_02_19_114040) do +ActiveRecord::Schema[8.0].define(version: 2026_02_26_101258) do create_table "moods", force: :cascade do |t| t.string "mode" t.datetime "recorded_at" @@ -48,6 +48,7 @@ ActiveRecord::Schema[8.0].define(version: 2026_02_19_114040) do t.datetime "invitation_accepted_at" t.string "username", null: false t.boolean "public", default: false + t.boolean "guess", default: false t.index ["email_address"], name: "index_users_on_email_address", unique: true end