Skip to content

Commit 1bbecd1

Browse files
committed
friendly_id fixes, annotate
1 parent 0ccb2be commit 1bbecd1

File tree

9 files changed

+91
-4
lines changed

9 files changed

+91
-4
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ gem "bootsnap", "~> 1.13", require: false
1212
gem "bootstrap", "~> 5.2"
1313
gem "cloudflare", "~> 4.3"
1414
gem "envkey", "~> 1.0"
15+
gem "friendly_id", "~> 5.5"
1516
gem "git", "~> 1.12"
1617
gem "haml", "~> 6.0"
1718
gem "hiredis", "~> 0.6"

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ GEM
156156
execjs (2.8.1)
157157
ffi (1.15.5)
158158
fiber-local (1.0.0)
159+
friendly_id (5.5.0)
160+
activerecord (>= 4.0.0)
159161
fugit (1.7.2)
160162
et-orbi (~> 1, >= 1.2.7)
161163
raabro (~> 1.4)
@@ -355,6 +357,7 @@ DEPENDENCIES
355357
database_consistency (~> 1.0)
356358
dotenv-rails (~> 2.8)
357359
envkey (~> 1.0)
360+
friendly_id (~> 5.5)
358361
git (~> 1.12)
359362
haml (~> 6.0)
360363
hiredis (~> 0.6)

app/models/doc.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
class Doc < ApplicationRecord
2-
include FriendlyId, LocalPath
2+
extend FriendlyId
3+
4+
include LocalPath
35

46
friendly_id :name, use: :slugged
57

@@ -30,3 +32,15 @@ def name
3032
end
3133
alias :to_s :name
3234
end
35+
36+
# == Schema Information
37+
#
38+
# Table name: docs
39+
#
40+
# id :integer not null, primary key
41+
# slug :string not null
42+
# tag :string
43+
# created_at :datetime
44+
# updated_at :datetime
45+
# project_id :integer
46+
#

app/models/doc_collection.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
class DocCollection < ApplicationRecord
2-
include FriendlyId, LocalPath
2+
extend FriendlyId
3+
4+
include LocalPath
35

46
friendly_id :name, use: :slugged
57

@@ -37,3 +39,16 @@ def uploaded?
3739
!!uploaded_at
3840
end
3941
end
42+
43+
# == Schema Information
44+
#
45+
# Table name: doc_collections
46+
#
47+
# id :integer not null, primary key
48+
# generated_at :datetime
49+
# generated_with :string
50+
# slug :string not null
51+
# uploaded_at :datetime
52+
# created_at :datetime
53+
# updated_at :datetime
54+
#

app/models/doc_collection_membership.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@ class DocCollectionMembership < ApplicationRecord
55
validates :doc, presence: true
66
validates :doc_id, uniqueness: { scope: :doc_collection_id }
77
end
8+
9+
# == Schema Information
10+
#
11+
# Table name: doc_collection_memberships
12+
#
13+
# id :integer not null, primary key
14+
# doc_collection_id :integer
15+
# doc_id :integer
16+
#

app/models/project.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
class Project < ApplicationRecord
2-
include FriendlyId, LocalPath
2+
extend FriendlyId
3+
4+
include LocalPath
35

46
friendly_id :name, use: :slugged
57

@@ -9,3 +11,17 @@ class Project < ApplicationRecord
911
validates :name, presence: true, uniqueness: true
1012
validates :git, presence: true, uniqueness: true
1113
end
14+
15+
# == Schema Information
16+
#
17+
# Table name: projects
18+
#
19+
# id :integer not null, primary key
20+
# git :string
21+
# links :text default([]), not null, is an Array
22+
# name :string
23+
# slug :string not null
24+
# tags :json
25+
# created_at :datetime
26+
# updated_at :datetime
27+
#

config/initializers/friendly_id.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FriendlyId.defaults do |config|
2+
config.use :reserved
3+
config.reserved_words = %w(new edit index session login logout users admin stylesheets assets javascripts images)
4+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class CreateFriendlyIdSlugs < ActiveRecord::Migration[7.0]
2+
def change
3+
create_table :friendly_id_slugs do |t|
4+
t.string :slug, null: false
5+
t.integer :sluggable_id, null: false
6+
t.string :sluggable_type, limit: 50
7+
t.string :scope
8+
t.datetime :created_at
9+
end
10+
add_index :friendly_id_slugs, [:sluggable_type, :sluggable_id]
11+
add_index :friendly_id_slugs, [:slug, :sluggable_type], length: {slug: 140, sluggable_type: 50}
12+
add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], length: {slug: 70, sluggable_type: 50, scope: 70}, unique: true
13+
end
14+
end

db/schema.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2018_09_02_164850) do
13+
ActiveRecord::Schema[7.0].define(version: 2022_12_04_174611) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "plpgsql"
1616

@@ -39,6 +39,17 @@
3939
t.index ["slug"], name: "index_docs_on_slug", unique: true
4040
end
4141

42+
create_table "friendly_id_slugs", force: :cascade do |t|
43+
t.string "slug", null: false
44+
t.integer "sluggable_id", null: false
45+
t.string "sluggable_type", limit: 50
46+
t.string "scope"
47+
t.datetime "created_at"
48+
t.index ["slug", "sluggable_type", "scope"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope", unique: true
49+
t.index ["slug", "sluggable_type"], name: "index_friendly_id_slugs_on_slug_and_sluggable_type"
50+
t.index ["sluggable_type", "sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_type_and_sluggable_id"
51+
end
52+
4253
create_table "projects", id: :serial, force: :cascade do |t|
4354
t.string "name"
4455
t.string "git"

0 commit comments

Comments
 (0)