From e6031abb288859ad9bf5a6665be68cae2ba2ce1e Mon Sep 17 00:00:00 2001 From: Felipe Joglar Date: Wed, 20 Mar 2024 09:32:54 +0100 Subject: [PATCH 1/9] Add Project model --- app/models/project.rb | 3 +++ db/migrate/20240320071340_create_projects.rb | 9 +++++++++ db/schema.rb | 8 +++++++- test/fixtures/projects.yml | 7 +++++++ test/models/project_test.rb | 9 +++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 app/models/project.rb create mode 100644 db/migrate/20240320071340_create_projects.rb create mode 100644 test/fixtures/projects.yml create mode 100644 test/models/project_test.rb diff --git a/app/models/project.rb b/app/models/project.rb new file mode 100644 index 0000000..3f00e16 --- /dev/null +++ b/app/models/project.rb @@ -0,0 +1,3 @@ +class Project < ApplicationRecord + validates :name, presence: true +end diff --git a/db/migrate/20240320071340_create_projects.rb b/db/migrate/20240320071340_create_projects.rb new file mode 100644 index 0000000..e2e511b --- /dev/null +++ b/db/migrate/20240320071340_create_projects.rb @@ -0,0 +1,9 @@ +class CreateProjects < ActiveRecord::Migration[7.1] + def change + create_table :projects do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 1c5310a..7a04d1e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,10 +10,16 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_02_01_003802) do +ActiveRecord::Schema[7.1].define(version: 2024_03_20_071340) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "projects", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "users", force: :cascade do |t| t.string "name", null: false t.string "email", null: false diff --git a/test/fixtures/projects.yml b/test/fixtures/projects.yml new file mode 100644 index 0000000..7d41224 --- /dev/null +++ b/test/fixtures/projects.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + +two: + name: MyString diff --git a/test/models/project_test.rb b/test/models/project_test.rb new file mode 100644 index 0000000..65beb61 --- /dev/null +++ b/test/models/project_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +class ProjectTest < ActiveSupport::TestCase + test "project attributes must not be empty" do + project = Project.new + assert project.invalid?, message: "Project without params should be invalid" + assert project.errors[:name].any?, message: "Expected name to be present" + end +end From cef6441ac9ce8c6b7ab9853c586d1fc84170c3f5 Mon Sep 17 00:00:00 2001 From: Felipe Joglar Date: Wed, 20 Mar 2024 10:34:03 +0100 Subject: [PATCH 2/9] Add association between User and Project --- app/models/project.rb | 4 +++- app/models/user.rb | 2 ++ .../20240320083301_add_user_ref_to_projects.rb | 5 +++++ db/schema.rb | 5 ++++- test/fixtures/projects.yml | 10 ++++++---- test/fixtures/users.yml | 14 +++++--------- test/models/project_test.rb | 2 ++ test/models/user_test.rb | 13 +++++++++++++ 8 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 db/migrate/20240320083301_add_user_ref_to_projects.rb diff --git a/app/models/project.rb b/app/models/project.rb index 3f00e16..a5d888c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,3 +1,5 @@ class Project < ApplicationRecord - validates :name, presence: true + belongs_to :user + + validates :name, :user_id, presence: true end diff --git a/app/models/user.rb b/app/models/user.rb index 0018cb2..779ccc1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,8 @@ class User < ApplicationRecord has_secure_password + has_many :projects, dependent: :destroy + EMAIL_REQUIREMENTS = URI::MailTo::EMAIL_REGEXP PASSWORD_REQUIREMENTS = /\A.{12,64}\z/ diff --git a/db/migrate/20240320083301_add_user_ref_to_projects.rb b/db/migrate/20240320083301_add_user_ref_to_projects.rb new file mode 100644 index 0000000..9ff9226 --- /dev/null +++ b/db/migrate/20240320083301_add_user_ref_to_projects.rb @@ -0,0 +1,5 @@ +class AddUserRefToProjects < ActiveRecord::Migration[7.1] + def change + add_reference :projects, :user, null: false, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 7a04d1e..4fd7b66 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: 2024_03_20_071340) do +ActiveRecord::Schema[7.1].define(version: 2024_03_20_083301) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -18,6 +18,8 @@ t.string "name" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.bigint "user_id", null: false + t.index ["user_id"], name: "index_projects_on_user_id" end create_table "users", force: :cascade do |t| @@ -29,4 +31,5 @@ t.index ["email"], name: "index_users_on_email", unique: true end + add_foreign_key "projects", "users" end diff --git a/test/fixtures/projects.yml b/test/fixtures/projects.yml index 7d41224..6ef7f2f 100644 --- a/test/fixtures/projects.yml +++ b/test/fixtures/projects.yml @@ -1,7 +1,9 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - name: MyString +inbox: + name: "Inbox" + user_id: 1 -two: - name: MyString +secret: + name: "Secret project" + user_id: 1 diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 58da1ef..f7e1319 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -1,11 +1,7 @@ # Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html -one: - name: MyString - email: aUniqueEmail - password_digest: MyString - -two: - name: MyString - email: anotherUniqueEmail - password_digest: MyString +felipe: + id: 1 + name: "Felipe" + email: "felipejoglar@taskodoro.com" + password_digest: "a_password_digest" diff --git a/test/models/project_test.rb b/test/models/project_test.rb index 65beb61..1817bca 100644 --- a/test/models/project_test.rb +++ b/test/models/project_test.rb @@ -1,9 +1,11 @@ require "test_helper" class ProjectTest < ActiveSupport::TestCase + test "project attributes must not be empty" do project = Project.new assert project.invalid?, message: "Project without params should be invalid" assert project.errors[:name].any?, message: "Expected name to be present" + assert project.errors[:user_id].any?, message: "Expected project to belong to an user" end end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 76069d2..6c5b2ab 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -52,6 +52,19 @@ class UserTest < ActiveSupport::TestCase assert_equal("an_email@email.com", user.email) end + test "projects are deleted along with user" do + user = valid_user + user.save! + user.projects.create(name: "Project 1") + user.projects.create(name: "Project 2") + + assert_equal 2, user.projects.size + + user.destroy! + + assert_equal 0, user.projects.size + end + private MIN_PASSWORD_LENGTH = 12 From 8aa4f2299be518d916b82f58d12e9b9abf5275ce Mon Sep 17 00:00:00 2001 From: Felipe Joglar Date: Wed, 20 Mar 2024 11:25:44 +0100 Subject: [PATCH 3/9] Extract `Resettable` concern from `User` model --- app/models/user.rb | 16 ++-------------- app/models/user/resettable.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 app/models/user/resettable.rb diff --git a/app/models/user.rb b/app/models/user.rb index 779ccc1..861e7a7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,6 @@ class User < ApplicationRecord + include Resettable + has_secure_password has_many :projects, dependent: :destroy @@ -12,18 +14,4 @@ class User < ApplicationRecord validates :password, format: PASSWORD_REQUIREMENTS normalizes :email, with: -> (email) { email.strip.downcase } - - def password_reset_requested - UserMailer.with(user: self, token: generate_token_for(:password_reset)) - .password_reset - .deliver_later - end - - private - - RESET_PASSWORD_TOKEN_EXPIRATION = 15.minutes - - generates_token_for :password_reset, expires_in: RESET_PASSWORD_TOKEN_EXPIRATION do - password_salt&.last(12) - end end diff --git a/app/models/user/resettable.rb b/app/models/user/resettable.rb new file mode 100644 index 0000000..d8ae247 --- /dev/null +++ b/app/models/user/resettable.rb @@ -0,0 +1,15 @@ +module User::Resettable + extend ActiveSupport::Concern + + included do + generates_token_for :password_reset, expires_in: 15.minutes do + password_salt&.last(12) + end + end + + def password_reset_requested + UserMailer.with(user: self, token: generate_token_for(:password_reset)) + .password_reset + .deliver_later + end +end From 8342fd3485183dbfb80fbc57267227c6955dbb6b Mon Sep 17 00:00:00 2001 From: Felipe Joglar Date: Wed, 20 Mar 2024 11:51:39 +0100 Subject: [PATCH 4/9] Improve routing file in a Rails way --- ...eset_controller.rb => passwords_controller.rb} | 6 +++--- app/views/landing/index.html.erb | 4 ++-- .../{password_reset => passwords}/edit.html.erb | 0 .../{password_reset => passwords}/new.html.erb | 0 app/views/sessions/new.html.erb | 2 +- app/views/user_mailer/password_reset.html.erb | 2 +- app/views/users/new.html.erb | 2 +- config/routes.rb | 15 +++++---------- ...oller_test.rb => passwords_controller_test.rb} | 10 +++++----- test/controllers/sessions_controller_test.rb | 4 ++-- test/controllers/users_controller_test.rb | 4 ++-- test/mailers/password_reset_mailer_test.rb | 2 +- 12 files changed, 23 insertions(+), 28 deletions(-) rename app/controllers/{password_reset_controller.rb => passwords_controller.rb} (69%) rename app/views/{password_reset => passwords}/edit.html.erb (100%) rename app/views/{password_reset => passwords}/new.html.erb (100%) rename test/controllers/{password_reset_controller_test.rb => passwords_controller_test.rb} (88%) diff --git a/app/controllers/password_reset_controller.rb b/app/controllers/passwords_controller.rb similarity index 69% rename from app/controllers/password_reset_controller.rb rename to app/controllers/passwords_controller.rb index 1de26d5..50693a8 100644 --- a/app/controllers/password_reset_controller.rb +++ b/app/controllers/passwords_controller.rb @@ -1,4 +1,4 @@ -class PasswordResetController < ApplicationController +class PasswordsController < ApplicationController skip_before_action :authenticate_user! before_action :user_by_token, only: [:edit, :update] @@ -8,7 +8,7 @@ def new def create User.find_by(email: params[:user][:email])&.password_reset_requested - redirect_to signin_path, notice: t("auth.password_reset.message.confirmation") + redirect_to new_signin_path, notice: t("auth.password_reset.message.confirmation") end def edit @@ -31,6 +31,6 @@ def password_params def user_by_token @user = User.find_by_token_for(:password_reset, params[:token]) - redirect_to forgot_password_path, notice: t("auth.password_reset.message.expired") unless @user.present? + redirect_to new_forgot_password_path, notice: t("auth.password_reset.message.expired") unless @user.present? end end diff --git a/app/views/landing/index.html.erb b/app/views/landing/index.html.erb index 6d1451d..4e8b9cf 100644 --- a/app/views/landing/index.html.erb +++ b/app/views/landing/index.html.erb @@ -5,10 +5,10 @@

<%= t("app_name") %>

- + <%= t("auth.signin") %> - + <%= t("auth.signup") %>
diff --git a/app/views/password_reset/edit.html.erb b/app/views/passwords/edit.html.erb similarity index 100% rename from app/views/password_reset/edit.html.erb rename to app/views/passwords/edit.html.erb diff --git a/app/views/password_reset/new.html.erb b/app/views/passwords/new.html.erb similarity index 100% rename from app/views/password_reset/new.html.erb rename to app/views/passwords/new.html.erb diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index 8fe4df0..355e2ec 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -20,6 +20,6 @@ <% end %>
- <%= link_to t("auth.sign_in.forgot_password"), forgot_password_path, class: "text-sm" %> + <%= link_to t("auth.sign_in.forgot_password"), new_forgot_password_path, class: "text-sm" %>
\ No newline at end of file diff --git a/app/views/user_mailer/password_reset.html.erb b/app/views/user_mailer/password_reset.html.erb index 788984a..3a3ae5b 100644 --- a/app/views/user_mailer/password_reset.html.erb +++ b/app/views/user_mailer/password_reset.html.erb @@ -1 +1 @@ -<%= link_to "Reset your password", password_edit_url(token: params[:token]) %> \ No newline at end of file +<%= link_to "Reset your password", edit_password_url(token: params[:token]) %> \ No newline at end of file diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index 917cc96..17acc28 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -32,6 +32,6 @@ <% end %>
- <%= t("auth.sign_up.already_signed_up") %> <%= link_to t("auth.signin"), signin_path %> + <%= t("auth.sign_up.already_signed_up") %> <%= link_to t("auth.signin"), new_signin_path %>
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index d969e1d..8dbdb80 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,17 +8,12 @@ # Defines the root path route ("/") root "landing#index" - post "signup", to: "users#create" - get "signup", to: "users#new" + resource :signup, only: %i[ create new ], controller: "users" + resource :signin, only: %i[ create new ], controller: "sessions" + resource :signout, only: %i[ destroy ], controller: "sessions" - post "signin", to: "sessions#create" - get "signin", to: "sessions#new" - delete "signout", to: "sessions#destroy" - - get "forgot_password", to: "password_reset#new" - post "password", to: "password_reset#create" - get "password/edit", to: "password_reset#edit" - patch "password", to: "password_reset#update" + resource :forgot_password, only: %i[ new ], controller: "passwords" + resource :password, only: %i[ create update edit ], controller: "passwords" get ":user_id", to: "home#index", as: :home end diff --git a/test/controllers/password_reset_controller_test.rb b/test/controllers/passwords_controller_test.rb similarity index 88% rename from test/controllers/password_reset_controller_test.rb rename to test/controllers/passwords_controller_test.rb index 6415c3c..9e88394 100644 --- a/test/controllers/password_reset_controller_test.rb +++ b/test/controllers/passwords_controller_test.rb @@ -1,13 +1,13 @@ require "test_helper" -class PasswordResetControllerTest < ActionDispatch::IntegrationTest +class PasswordsControllerTest < ActionDispatch::IntegrationTest setup do @name = "Felipe" @token = create_user_with(name: @name).generate_token_for(:password_reset) end test "requesting to create a new password" do - get forgot_password_url + get new_forgot_password_url assert_response :ok assert_select 'h2', I18n .t("auth.forgot_password.title") @@ -20,7 +20,7 @@ class PasswordResetControllerTest < ActionDispatch::IntegrationTest end test "updating a password" do - get password_edit_url, params: { token: @token } + get edit_password_url, params: { token: @token } assert_response :ok assert_select 'h2', I18n.t("auth.password_reset.title") @@ -34,7 +34,7 @@ class PasswordResetControllerTest < ActionDispatch::IntegrationTest end test "failing to update a password with invalid token" do - get password_edit_url, params: { token: @token } + get edit_password_url, params: { token: @token } assert_response :ok assert_select 'h2', I18n.t("auth.password_reset.title") @@ -47,7 +47,7 @@ class PasswordResetControllerTest < ActionDispatch::IntegrationTest end test "failing to update a password with invalid password" do - get password_edit_url, params: { token: @token } + get edit_password_url, params: { token: @token } assert_response :ok assert_select 'h2', I18n.t("auth.password_reset.title") diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb index 3993be0..659594c 100644 --- a/test/controllers/sessions_controller_test.rb +++ b/test/controllers/sessions_controller_test.rb @@ -6,7 +6,7 @@ class SessionsControllerTest < ActionDispatch::IntegrationTest email = "felipe@taskodoro.com" password = "a_valid_password" - get signin_url + get new_signin_url assert_response :ok assert_select 'h2', I18n.t("auth.sign_in.title") @@ -25,7 +25,7 @@ class SessionsControllerTest < ActionDispatch::IntegrationTest email = "felipe@taskodoro.com" password = "a_valid_password" - get signin_url + get new_signin_url assert_response :ok assert_select 'h2', I18n.t("auth.sign_in.title") diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 0205b58..6d6c348 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb @@ -3,7 +3,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest test "creating a new user" do - get signup_url + get new_signup_url assert_response :ok assert_select 'h2', I18n.t("auth.sign_up.title") @@ -17,7 +17,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest end test "failing to create a new user" do - get signup_url + get new_signup_url assert_response :ok assert_select 'h2', I18n.t("auth.sign_up.title") diff --git a/test/mailers/password_reset_mailer_test.rb b/test/mailers/password_reset_mailer_test.rb index 0964a37..fb2a46f 100644 --- a/test/mailers/password_reset_mailer_test.rb +++ b/test/mailers/password_reset_mailer_test.rb @@ -2,7 +2,7 @@ class UserMailerTest < ActionMailer::TestCase - test "password_reset sends the token in the URL" do + test "passwords sends the token in the URL" do email = "an_email@email.com" token = "a_token" From 0c9b9d31810bc8e9ad386a56289a43658689682b Mon Sep 17 00:00:00 2001 From: Felipe Joglar Date: Wed, 20 Mar 2024 11:54:40 +0100 Subject: [PATCH 5/9] Create `ProjectsController` and add it as entry point --- app/controllers/home_controller.rb | 4 ---- app/controllers/projects_controller.rb | 4 ++++ app/views/{home => projects}/index.html.erb | 0 config/routes.rb | 6 +++++- 4 files changed, 9 insertions(+), 5 deletions(-) delete mode 100644 app/controllers/home_controller.rb create mode 100644 app/controllers/projects_controller.rb rename app/views/{home => projects}/index.html.erb (100%) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb deleted file mode 100644 index 95f2992..0000000 --- a/app/controllers/home_controller.rb +++ /dev/null @@ -1,4 +0,0 @@ -class HomeController < ApplicationController - def index - end -end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb new file mode 100644 index 0000000..02ef338 --- /dev/null +++ b/app/controllers/projects_controller.rb @@ -0,0 +1,4 @@ +class ProjectsController < ApplicationController + def index + end +end diff --git a/app/views/home/index.html.erb b/app/views/projects/index.html.erb similarity index 100% rename from app/views/home/index.html.erb rename to app/views/projects/index.html.erb diff --git a/config/routes.rb b/config/routes.rb index 8dbdb80..72f102c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,5 +15,9 @@ resource :forgot_password, only: %i[ new ], controller: "passwords" resource :password, only: %i[ create update edit ], controller: "passwords" - get ":user_id", to: "home#index", as: :home + scope ":user_id", constraints: { user_id: /\d+/ } do + get "/", to: "projects#index", as: :home + + resources :projects + end end From 9ddda8acc8a45f931d9180cc660ddf5276f9103f Mon Sep 17 00:00:00 2001 From: Felipe Joglar Date: Wed, 20 Mar 2024 12:47:27 +0100 Subject: [PATCH 6/9] Create default "Inbox" project after creation --- app/models/user.rb | 8 ++++++++ test/models/user_test.rb | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 861e7a7..8d482ad 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,6 +5,8 @@ class User < ApplicationRecord has_many :projects, dependent: :destroy + after_create :create_default_project + EMAIL_REQUIREMENTS = URI::MailTo::EMAIL_REGEXP PASSWORD_REQUIREMENTS = /\A.{12,64}\z/ @@ -14,4 +16,10 @@ class User < ApplicationRecord validates :password, format: PASSWORD_REQUIREMENTS normalizes :email, with: -> (email) { email.strip.downcase } + + private + + def create_default_project + self.projects.create(name: "Inbox") + end end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 6c5b2ab..b703021 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -58,13 +58,21 @@ class UserTest < ActiveSupport::TestCase user.projects.create(name: "Project 1") user.projects.create(name: "Project 2") - assert_equal 2, user.projects.size + assert user.projects.any? user.destroy! assert_equal 0, user.projects.size end + test "creates default project after creation" do + user = valid_user + user.save! + + assert_equal 1, user.projects.size + assert_equal "Inbox", user.projects.first!.name + end + private MIN_PASSWORD_LENGTH = 12 From df679f352a9dae953913c746f875dabf3b69958a Mon Sep 17 00:00:00 2001 From: Felipe Joglar Date: Wed, 20 Mar 2024 13:45:06 +0100 Subject: [PATCH 7/9] Minor refactor in routing --- config/routes.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 72f102c..0e906fd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,9 +10,9 @@ resource :signup, only: %i[ create new ], controller: "users" resource :signin, only: %i[ create new ], controller: "sessions" - resource :signout, only: %i[ destroy ], controller: "sessions" + resource :signout, only: :destroy, controller: "sessions" - resource :forgot_password, only: %i[ new ], controller: "passwords" + resource :forgot_password, only: :new, controller: "passwords" resource :password, only: %i[ create update edit ], controller: "passwords" scope ":user_id", constraints: { user_id: /\d+/ } do From 9f062e63a3574bdb17f23e039abe84f10b969182 Mon Sep 17 00:00:00 2001 From: Felipe Joglar Date: Wed, 20 Mar 2024 15:36:56 +0100 Subject: [PATCH 8/9] Remove unneeded helper methods from Authentication concern --- app/controllers/concerns/authentication.rb | 4 ---- app/views/projects/index.html.erb | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/app/controllers/concerns/authentication.rb b/app/controllers/concerns/authentication.rb index c68312f..e20d830 100644 --- a/app/controllers/concerns/authentication.rb +++ b/app/controllers/concerns/authentication.rb @@ -1,10 +1,6 @@ module Authentication extend ActiveSupport::Concern - included do - helper_method :current_user, :user_signed_in? - end - def sign_in(user) reset_session session[:current_user_id] = user.id diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb index 172f0df..bc86046 100644 --- a/app/views/projects/index.html.erb +++ b/app/views/projects/index.html.erb @@ -1,2 +1,2 @@ -

Welcome <%= current_user.name %>

+

Welcome <%= Current.user.name %>

<%= button_to "Logout", signout_path, method: :delete %> \ No newline at end of file From 3d09dd439d2bd27c555f69322b584a699c7d4659 Mon Sep 17 00:00:00 2001 From: Felipe Joglar Date: Thu, 21 Mar 2024 10:15:49 +0100 Subject: [PATCH 9/9] Add projects listed in home --- app/controllers/projects_controller.rb | 1 + app/views/projects/index.html.erb | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 02ef338..defd28a 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,4 +1,5 @@ class ProjectsController < ApplicationController def index + @projects = Current.user.projects.all end end diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb index bc86046..d50498e 100644 --- a/app/views/projects/index.html.erb +++ b/app/views/projects/index.html.erb @@ -1,2 +1,7 @@

Welcome <%= Current.user.name %>

-<%= button_to "Logout", signout_path, method: :delete %> \ No newline at end of file +<%= button_to "Logout", signout_path, method: :delete %> +
    + <% @projects.each do |project| %> +
  • <%= project.name %>

  • + <% end %> +