From 49b11f2864f75bcfb8d0d01439939ed68aa90b8f Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 2 Jul 2018 18:03:37 -0400 Subject: Collapsed Entry -> Blog single-table inheritance to Blog --- app/controllers/blogs_controller.rb | 7 +++++++ app/controllers/entries_controller.rb | 7 ------- app/models/blog.rb | 12 ++++++++++-- app/models/entry.rb | 11 ----------- app/views/blogs/show.html.haml | 2 ++ app/views/entries/show.html.haml | 2 -- app/views/records/index.html.haml | 2 +- 7 files changed, 20 insertions(+), 23 deletions(-) create mode 100644 app/controllers/blogs_controller.rb delete mode 100644 app/controllers/entries_controller.rb delete mode 100644 app/models/entry.rb create mode 100644 app/views/blogs/show.html.haml delete mode 100644 app/views/entries/show.html.haml (limited to 'app') 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 @@ +class BlogsController < ApplicationController + + def show + @blog = Blog.find_by_slug(params[:slug]) + end + +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 @@ -class EntriesController < ApplicationController - - def show - @entry = Entry.find_by_slug(params[:slug]) - end - -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 @@ -class Blog < Entry +class Blog < ApplicationRecord + has_many :records, as: :recordable, inverse_of: :recordable + validates :title, :body, presence: true -end + validates :slug, presence: true, format: /\A[-a-z0-9]+\z/ + accepts_nested_attributes_for :records, allow_destroy: true + + def path + "/says/#{slug}" + end +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 @@ -class Entry < ApplicationRecord - has_many :records, as: :recordable, inverse_of: :recordable - - validates :slug, presence: true, format: /\A[-a-z0-9]+\z/ - - accepts_nested_attributes_for :records, allow_destroy: true - - def path - "/says/#{slug}" - end -end diff --git a/app/views/blogs/show.html.haml b/app/views/blogs/show.html.haml new file mode 100644 index 0000000..51d4aa0 --- /dev/null +++ b/app/views/blogs/show.html.haml @@ -0,0 +1,2 @@ +.breadcrumb= link_to "← Back to home page", root_path += render @blog diff --git a/app/views/entries/show.html.haml b/app/views/entries/show.html.haml deleted file mode 100644 index 3a9337c..0000000 --- a/app/views/entries/show.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -.breadcrumb= link_to "← Back to home page", root_path -= render @entry 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 @@ %span.description= link_to record.description, record.recordable.path %ul.tags %li.record-date= record.created_at.strftime("%m.%d.%y") - %li.entry-type{ class: "entry-type-#{record.recordable.type.downcase}" }= record.recordable.type + %li.entry-type{ class: "entry-type-#{record.recordable_type.downcase}" }= record.recordable_type -- cgit 1.4.1