Skip to content

Commit

Permalink
Added friendly id to enrollments
Browse files Browse the repository at this point in the history
  • Loading branch information
dalvarez2596 committed Nov 5, 2024
1 parent 26daf0d commit 564a00a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/enrollments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def destroy

private
def set_enrollment
@enrollment = Enrollment.find(params[:id])
@enrollment = Enrollment.friendly.find(params[:id])
end

def enrollment_params
Expand Down
3 changes: 3 additions & 0 deletions app/models/enrollment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class Enrollment < ApplicationRecord

scope :pending_review, -> { where(rating: [ 0, nil, "" ], review: [ 0, nil, "" ]) }

extend FriendlyId
friendly_id :to_s, use: :slugged

def to_s
user.to_s + " " + course.to_s
end
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20241105180726_add_slug_to_enrollments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddSlugToEnrollments < ActiveRecord::Migration[7.2]
def change
add_column :enrollments, :slug, :string
add_index :enrollments, :slug, unique: true
end
end
4 changes: 3 additions & 1 deletion db/schema.rb

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

0 comments on commit 564a00a

Please sign in to comment.