Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 84 #39

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/models/enrollment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Enrollment < ApplicationRecord
belongs_to :course
belongs_to :course, counter_cache: true
# Course.find_each{ |course| Course.reset_counters(course.id, :enrollments)}
belongs_to :user

validates :user, :course, presence: true
6 changes: 5 additions & 1 deletion app/views/courses/_course.html.haml
Original file line number Diff line number Diff line change
@@ -11,7 +11,11 @@
= review_button(course)
.card-footer
.text-warning.fa.fa-star
= course.average_rating
%b= course.average_rating
-# Enrollments count:
-# = course.enrollments.count
Counter cache enrollments count:
= course.enrollments_count
.card-footer
.fa.fa-list-check
= course.lessons.count
5 changes: 5 additions & 0 deletions db/migrate/20241111183829_add_counter_cache_to_models.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCounterCacheToModels < ActiveRecord::Migration[7.2]
def change
add_column :courses, :enrollments_count, :integer, null: false, default: 0
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.


Unchanged files with check annotations Beta

# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class
# with default "from" parameter.
config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'

Check failure on line 27 in config/initializers/devise.rb

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
# Configure the class responsible to send e-mails.
# config.mailer = 'Devise::Mailer'
# Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be
# available as additional gems.
require 'devise/orm/active_record'

Check failure on line 39 in config/initializers/devise.rb

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
# ==> Configuration for any authentication mechanism
# Configure which keys are used when authenticating a user. The default is
# Configure which authentication keys should be case-insensitive.
# These keys will be downcased upon creating or modifying a user and when used
# to authenticate or find a user. Default is :email.
config.case_insensitive_keys = [:email]

Check failure on line 61 in config/initializers/devise.rb

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.

Check failure on line 61 in config/initializers/devise.rb

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.
# Configure which authentication keys should have whitespace stripped.
# These keys will have whitespace before and after removed upon creating or
# modifying a user and when used to authenticate or find a user. Default is :email.
config.strip_whitespace_keys = [:email]

Check failure on line 66 in config/initializers/devise.rb

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.

Check failure on line 66 in config/initializers/devise.rb

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.
# Tell if authentication through request.params is enabled. True by default.
# It can be set to an array that will enable params authentication only for the
# Notice that if you are skipping storage for all authentication paths, you
# may want to disable generating routes to Devise's sessions controller by
# passing skip: :sessions to `devise_for` in your config/routes.rb
config.skip_session_storage = [:http_auth]

Check failure on line 100 in config/initializers/devise.rb

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.

Check failure on line 100 in config/initializers/devise.rb

GitHub Actions / lint

Layout/SpaceInsideArrayLiteralBrackets: Use space inside array brackets.
# By default, Devise cleans up the CSRF token on authentication to
# avoid CSRF token fixation attacks. This means that, when using AJAX
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
# Default class for buttons
config.button_class = 'btn'

Check failure on line 16 in config/initializers/simple_form_bootstrap.rb

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
# Define the default class of the input wrapper of the boolean input.
config.boolean_label_class = 'form-check-label'

Check failure on line 19 in config/initializers/simple_form_bootstrap.rb

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
# How the label text should be generated altogether with the required text.
config.label_text = lambda { |label, required, explicit_label| "#{label} #{required}" }