diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index b9762046b93d6629f567569aab2c4bbe3479dc9e..eb1b823e2f152dfd025bef367646a32874028550 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,4 @@ class ApplicationMailer < ActionMailer::Base - default to: 'admin@team.com', from: 'a@customer.com' + default to: 'admin@team.com', from: 'a@customer.com' # Mailer defaults layout 'mailer' end diff --git a/app/mailers/contact_mailer.rb b/app/mailers/contact_mailer.rb index 6de699adfcb61efac8465ac86ca31d10662b8542..f8e77375a4dcfab465110ba0b50215b233ba09c4 100644 --- a/app/mailers/contact_mailer.rb +++ b/app/mailers/contact_mailer.rb @@ -1,6 +1,6 @@ class ContactMailer < ApplicationMailer - def contact_email(email, message) + def contact_email(email, message) # Handling of mail @email = email @message = message diff --git a/app/models/list.rb b/app/models/list.rb index 1526ca640e838f7605c4c96f86d0a88da944d7a1..7cec1b663e9380046f08941b890a93521cf2078d 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -1,9 +1,9 @@ class List < ApplicationRecord - belongs_to :user - validates :name, presence: true - validates :user_id, presence: true + belongs_to :user # A list is owned by a user + validates :name, presence: true # A list should not exist without a name + validates :user_id, presence: true # A list should not exist without an id reference to its user - has_many :products, dependent: :destroy + has_many :products, dependent: :destroy # Each list owns a collection of products - scope :user, ->(user_id) { where(user_id: user_id) } + scope :user, ->(user_id) { where(user_id: user_id) } # A scope that only returns the lists owned by a user of specified user_id end diff --git a/app/models/product.rb b/app/models/product.rb index ab5c0d23fa86ee47e019ed4f1458d962b9efaad0..a49321e6e9f7d2f62cf0d456e12eb5fab9fc9108 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -1,8 +1,8 @@ class Product < ApplicationRecord - belongs_to :list - validates :name, presence: true - validates :acquired, inclusion: {in: [true, false]} - validates :list_id, presence: true + belongs_to :list # Every product belongs to a list + validates :name, presence: true # A product should not exist without a name + validates :acquired, inclusion: {in: [true, false]} # The "acquired" field of a product should be either true or false + validates :list_id, presence: true # A product should not exist without reference to its parent list - scope :list, ->(list_id) { where(list_id: list_id) } + scope :list, ->(list_id) { where(list_id: list_id) } # A scope that returns all products in a specified list end diff --git a/app/models/user.rb b/app/models/user.rb index fb5729da945a36743bcae298aad9ecbed3d2bc0e..03095d04b7bd8561beb9d0cfc8dc04963712e632 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,7 +1,7 @@ class User < ApplicationRecord - validates :name, presence: true - validates :email, presence: true, uniqueness: true - validates :password, presence: true + validates :name, presence: true # A user should not exist without a name + validates :email, presence: true, uniqueness: true # A user should not exist without a unique email address + validates :password, presence: true # A user should not exist without a password - has_many :lists, dependent: :destroy + has_many :lists, dependent: :destroy # Each user owns a collection of lists end