diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-07-02 18:03:37 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-07-03 14:01:41 -0400 |
commit | 49b11f2864f75bcfb8d0d01439939ed68aa90b8f (patch) | |
tree | c91d0976e9cb54562aa2c19f9648235d74f14cbf | |
parent | cb01d13034ad41a29533b623cbbf7c23b37a231c (diff) | |
download | thoughts-49b11f2864f75bcfb8d0d01439939ed68aa90b8f.tar.gz thoughts-49b11f2864f75bcfb8d0d01439939ed68aa90b8f.tar.bz2 thoughts-49b11f2864f75bcfb8d0d01439939ed68aa90b8f.zip |
Collapsed Entry -> Blog single-table inheritance to Blog
-rw-r--r-- | app/controllers/blogs_controller.rb | 7 | ||||
-rw-r--r-- | app/controllers/entries_controller.rb | 7 | ||||
-rw-r--r-- | app/models/blog.rb | 12 | ||||
-rw-r--r-- | app/models/entry.rb | 11 | ||||
-rw-r--r-- | app/views/blogs/show.html.haml (renamed from app/views/entries/show.html.haml) | 2 | ||||
-rw-r--r-- | app/views/records/index.html.haml | 2 | ||||
-rw-r--r-- | config/routes.rb | 2 | ||||
-rw-r--r-- | db/migrate/20180702214240_rename_entries_to_blogs.rb | 24 | ||||
-rw-r--r-- | db/schema.rb | 45 |
9 files changed, 66 insertions, 46 deletions
diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb new file mode 100644 index 0000000..5e72601 --- /dev/null +++ b/app/controllers/blogs_controller.rb | |||
@@ -0,0 +1,7 @@ | |||
1 | class BlogsController < ApplicationController | ||
2 | |||
3 | def show | ||
4 | @blog = Blog.find_by_slug(params[:slug]) | ||
5 | end | ||
6 | |||
7 | end | ||
diff --git a/app/controllers/entries_controller.rb b/app/controllers/entries_controller.rb deleted file mode 100644 index 14d779a..0000000 --- a/app/controllers/entries_controller.rb +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | class EntriesController < ApplicationController | ||
2 | |||
3 | def show | ||
4 | @entry = Entry.find_by_slug(params[:slug]) | ||
5 | end | ||
6 | |||
7 | end | ||
diff --git a/app/models/blog.rb b/app/models/blog.rb index d2b1c27..1ace11b 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb | |||
@@ -1,4 +1,12 @@ | |||
1 | class Blog < Entry | 1 | class Blog < ApplicationRecord |
2 | has_many :records, as: :recordable, inverse_of: :recordable | ||
3 | |||
2 | validates :title, :body, presence: true | 4 | validates :title, :body, presence: true |
3 | end | 5 | validates :slug, presence: true, format: /\A[-a-z0-9]+\z/ |
4 | 6 | ||
7 | accepts_nested_attributes_for :records, allow_destroy: true | ||
8 | |||
9 | def path | ||
10 | "/says/#{slug}" | ||
11 | end | ||
12 | end | ||
diff --git a/app/models/entry.rb b/app/models/entry.rb deleted file mode 100644 index 87fd46d..0000000 --- a/app/models/entry.rb +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | class Entry < ApplicationRecord | ||
2 | has_many :records, as: :recordable, inverse_of: :recordable | ||
3 | |||
4 | validates :slug, presence: true, format: /\A[-a-z0-9]+\z/ | ||
5 | |||
6 | accepts_nested_attributes_for :records, allow_destroy: true | ||
7 | |||
8 | def path | ||
9 | "/says/#{slug}" | ||
10 | end | ||
11 | end | ||
diff --git a/app/views/entries/show.html.haml b/app/views/blogs/show.html.haml index 3a9337c..51d4aa0 100644 --- a/app/views/entries/show.html.haml +++ b/app/views/blogs/show.html.haml | |||
@@ -1,2 +1,2 @@ | |||
1 | .breadcrumb= link_to "← Back to home page", root_path | 1 | .breadcrumb= link_to "← Back to home page", root_path |
2 | = render @entry | 2 | = render @blog |
diff --git a/app/views/records/index.html.haml b/app/views/records/index.html.haml index 3850d72..200321e 100644 --- a/app/views/records/index.html.haml +++ b/app/views/records/index.html.haml | |||
@@ -4,4 +4,4 @@ | |||
4 | %span.description= link_to record.description, record.recordable.path | 4 | %span.description= link_to record.description, record.recordable.path |
5 | %ul.tags | 5 | %ul.tags |
6 | %li.record-date= record.created_at.strftime("%m.%d.%y") | 6 | %li.record-date= record.created_at.strftime("%m.%d.%y") |
7 | %li.entry-type{ class: "entry-type-#{record.recordable.type.downcase}" }= record.recordable.type | 7 | %li.entry-type{ class: "entry-type-#{record.recordable_type.downcase}" }= record.recordable_type |
diff --git a/config/routes.rb b/config/routes.rb index 1216b85..cf0bdd6 100644 --- a/config/routes.rb +++ b/config/routes.rb | |||
@@ -14,7 +14,7 @@ Rails.application.routes.draw do | |||
14 | 14 | ||
15 | root "records#index" | 15 | root "records#index" |
16 | 16 | ||
17 | get 'says/:slug', to: 'entries#show' | 17 | get 'says/:slug', to: 'blogs#show' |
18 | 18 | ||
19 | mount Pokeviewer::Engine => '/poke3' | 19 | mount Pokeviewer::Engine => '/poke3' |
20 | end | 20 | end |
diff --git a/db/migrate/20180702214240_rename_entries_to_blogs.rb b/db/migrate/20180702214240_rename_entries_to_blogs.rb new file mode 100644 index 0000000..eac2e6a --- /dev/null +++ b/db/migrate/20180702214240_rename_entries_to_blogs.rb | |||
@@ -0,0 +1,24 @@ | |||
1 | class RenameEntriesToBlogs < ActiveRecord::Migration[5.1] | ||
2 | def up | ||
3 | rename_table :entries, :blogs | ||
4 | |||
5 | remove_column :blogs, :type | ||
6 | |||
7 | Record.where(recordable_type: "Entry").each do |r| | ||
8 | r.recordable_type = "Blog" | ||
9 | r.save! | ||
10 | end | ||
11 | end | ||
12 | |||
13 | def down | ||
14 | rename_table :blogs, :entries | ||
15 | |||
16 | add_column :entries, :type, :string, null: false, default: "Blog" | ||
17 | change_column_default :entries, :type, nil | ||
18 | |||
19 | Record.where(recordable_type: "Blog").each do |r| | ||
20 | r.recordable_type = "Entry" | ||
21 | r.save! | ||
22 | end | ||
23 | end | ||
24 | end | ||
diff --git a/db/schema.rb b/db/schema.rb index 868f6f6..e036b75 100644 --- a/db/schema.rb +++ b/db/schema.rb | |||
@@ -10,9 +10,17 @@ | |||
10 | # | 10 | # |
11 | # It's strongly recommended that you check this file into your version control system. | 11 | # It's strongly recommended that you check this file into your version control system. |
12 | 12 | ||
13 | ActiveRecord::Schema.define(version: 20180130021851) do | 13 | ActiveRecord::Schema.define(version: 20180702214240) do |
14 | 14 | ||
15 | create_table "ckeditor_assets", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" do |t| | 15 | create_table "blogs", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| |
16 | t.string "title" | ||
17 | t.text "body" | ||
18 | t.string "slug", null: false | ||
19 | t.datetime "created_at", null: false | ||
20 | t.datetime "updated_at", null: false | ||
21 | end | ||
22 | |||
23 | create_table "ckeditor_assets", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| | ||
16 | t.string "data_file_name", null: false | 24 | t.string "data_file_name", null: false |
17 | t.string "data_content_type" | 25 | t.string "data_content_type" |
18 | t.integer "data_file_size" | 26 | t.integer "data_file_size" |
@@ -25,16 +33,7 @@ ActiveRecord::Schema.define(version: 20180130021851) do | |||
25 | t.index ["type"], name: "index_ckeditor_assets_on_type" | 33 | t.index ["type"], name: "index_ckeditor_assets_on_type" |
26 | end | 34 | end |
27 | 35 | ||
28 | create_table "entries", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" do |t| | 36 | create_table "pokeviewer_abilities", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| |
29 | t.string "title" | ||
30 | t.text "body" | ||
31 | t.string "slug", null: false | ||
32 | t.string "type", null: false | ||
33 | t.datetime "created_at", null: false | ||
34 | t.datetime "updated_at", null: false | ||
35 | end | ||
36 | |||
37 | create_table "pokeviewer_abilities", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" do |t| | ||
38 | t.string "name", null: false | 37 | t.string "name", null: false |
39 | t.string "description", null: false | 38 | t.string "description", null: false |
40 | t.datetime "created_at", null: false | 39 | t.datetime "created_at", null: false |
@@ -42,13 +41,13 @@ ActiveRecord::Schema.define(version: 20180130021851) do | |||
42 | t.index ["name"], name: "index_pokeviewer_abilities_on_name", unique: true | 41 | t.index ["name"], name: "index_pokeviewer_abilities_on_name", unique: true |
43 | end | 42 | end |
44 | 43 | ||
45 | create_table "pokeviewer_gift_ribbons", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" do |t| | 44 | create_table "pokeviewer_gift_ribbons", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| |
46 | t.string "description", null: false | 45 | t.string "description", null: false |
47 | t.datetime "created_at", null: false | 46 | t.datetime "created_at", null: false |
48 | t.datetime "updated_at", null: false | 47 | t.datetime "updated_at", null: false |
49 | end | 48 | end |
50 | 49 | ||
51 | create_table "pokeviewer_items", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" do |t| | 50 | create_table "pokeviewer_items", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| |
52 | t.string "name", null: false | 51 | t.string "name", null: false |
53 | t.boolean "tm", default: false, null: false | 52 | t.boolean "tm", default: false, null: false |
54 | t.integer "move_id" | 53 | t.integer "move_id" |
@@ -60,13 +59,13 @@ ActiveRecord::Schema.define(version: 20180130021851) do | |||
60 | t.index ["move_id"], name: "index_pokeviewer_items_on_move_id" | 59 | t.index ["move_id"], name: "index_pokeviewer_items_on_move_id" |
61 | end | 60 | end |
62 | 61 | ||
63 | create_table "pokeviewer_locations", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" do |t| | 62 | create_table "pokeviewer_locations", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| |
64 | t.string "name", null: false | 63 | t.string "name", null: false |
65 | t.datetime "created_at", null: false | 64 | t.datetime "created_at", null: false |
66 | t.datetime "updated_at", null: false | 65 | t.datetime "updated_at", null: false |
67 | end | 66 | end |
68 | 67 | ||
69 | create_table "pokeviewer_moves", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" do |t| | 68 | create_table "pokeviewer_moves", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| |
70 | t.string "name", null: false | 69 | t.string "name", null: false |
71 | t.integer "pp", null: false | 70 | t.integer "pp", null: false |
72 | t.datetime "created_at", null: false | 71 | t.datetime "created_at", null: false |
@@ -78,7 +77,7 @@ ActiveRecord::Schema.define(version: 20180130021851) do | |||
78 | t.index ["name"], name: "index_pokeviewer_moves_on_name", unique: true | 77 | t.index ["name"], name: "index_pokeviewer_moves_on_name", unique: true |
79 | end | 78 | end |
80 | 79 | ||
81 | create_table "pokeviewer_pokedex_entries", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" do |t| | 80 | create_table "pokeviewer_pokedex_entries", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| |
82 | t.bigint "trainer_id" | 81 | t.bigint "trainer_id" |
83 | t.bigint "species_id" | 82 | t.bigint "species_id" |
84 | t.boolean "caught", default: false | 83 | t.boolean "caught", default: false |
@@ -89,7 +88,7 @@ ActiveRecord::Schema.define(version: 20180130021851) do | |||
89 | t.index ["trainer_id"], name: "index_pokeviewer_pokedex_entries_on_trainer_id" | 88 | t.index ["trainer_id"], name: "index_pokeviewer_pokedex_entries_on_trainer_id" |
90 | end | 89 | end |
91 | 90 | ||
92 | create_table "pokeviewer_pokemon", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" do |t| | 91 | create_table "pokeviewer_pokemon", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| |
93 | t.string "uuid", null: false | 92 | t.string "uuid", null: false |
94 | t.integer "trainer_id" | 93 | t.integer "trainer_id" |
95 | t.string "key" | 94 | t.string "key" |
@@ -116,7 +115,7 @@ ActiveRecord::Schema.define(version: 20180130021851) do | |||
116 | t.index ["uuid"], name: "index_pokeviewer_pokemon_on_uuid", unique: true | 115 | t.index ["uuid"], name: "index_pokeviewer_pokemon_on_uuid", unique: true |
117 | end | 116 | end |
118 | 117 | ||
119 | create_table "pokeviewer_revisions", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" do |t| | 118 | create_table "pokeviewer_revisions", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| |
120 | t.integer "pokemon_id", null: false | 119 | t.integer "pokemon_id", null: false |
121 | t.integer "sequential_id", null: false | 120 | t.integer "sequential_id", null: false |
122 | t.string "nickname", null: false | 121 | t.string "nickname", null: false |
@@ -172,7 +171,7 @@ ActiveRecord::Schema.define(version: 20180130021851) do | |||
172 | t.index ["species_id"], name: "index_pokeviewer_revisions_on_species_id" | 171 | t.index ["species_id"], name: "index_pokeviewer_revisions_on_species_id" |
173 | end | 172 | end |
174 | 173 | ||
175 | create_table "pokeviewer_species", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" do |t| | 174 | create_table "pokeviewer_species", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| |
176 | t.string "name", null: false | 175 | t.string "name", null: false |
177 | t.datetime "created_at", null: false | 176 | t.datetime "created_at", null: false |
178 | t.datetime "updated_at", null: false | 177 | t.datetime "updated_at", null: false |
@@ -183,7 +182,7 @@ ActiveRecord::Schema.define(version: 20180130021851) do | |||
183 | t.index ["name"], name: "index_pokeviewer_species_on_name", unique: true | 182 | t.index ["name"], name: "index_pokeviewer_species_on_name", unique: true |
184 | end | 183 | end |
185 | 184 | ||
186 | create_table "pokeviewer_trainers", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" do |t| | 185 | create_table "pokeviewer_trainers", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| |
187 | t.string "game", null: false | 186 | t.string "game", null: false |
188 | t.string "name", null: false | 187 | t.string "name", null: false |
189 | t.integer "number", null: false | 188 | t.integer "number", null: false |
@@ -220,7 +219,7 @@ ActiveRecord::Schema.define(version: 20180130021851) do | |||
220 | t.index ["world_ribbon_id"], name: "index_pokeviewer_trainers_on_world_ribbon_id" | 219 | t.index ["world_ribbon_id"], name: "index_pokeviewer_trainers_on_world_ribbon_id" |
221 | end | 220 | end |
222 | 221 | ||
223 | create_table "records", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" do |t| | 222 | create_table "records", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| |
224 | t.text "description" | 223 | t.text "description" |
225 | t.string "recordable_type" | 224 | t.string "recordable_type" |
226 | t.integer "recordable_id" | 225 | t.integer "recordable_id" |
@@ -229,7 +228,7 @@ ActiveRecord::Schema.define(version: 20180130021851) do | |||
229 | t.index ["recordable_type", "recordable_id"], name: "index_records_on_recordable_type_and_recordable_id" | 228 | t.index ["recordable_type", "recordable_id"], name: "index_records_on_recordable_type_and_recordable_id" |
230 | end | 229 | end |
231 | 230 | ||
232 | create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" do |t| | 231 | create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| |
233 | t.string "login", default: "", null: false | 232 | t.string "login", default: "", null: false |
234 | t.string "email", default: "", null: false | 233 | t.string "email", default: "", null: false |
235 | t.string "encrypted_password", default: "", null: false | 234 | t.string "encrypted_password", default: "", null: false |