From 27067b4d8e5e854f16e3bdb08c2f63f4250632a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstro=CC=88m?= Date: Wed, 3 Mar 2021 14:36:03 +0100 Subject: Add 'url' field to config table --- interfaces/http/web/views/index.erb | 9 +++++++-- interfaces/http/web/views/not_found.erb | 2 +- interfaces/http/web/views/post.erb | 9 +++++++-- interfaces/ruby/models/config.rb | 14 ++++++++++++-- interfaces/ruby/models/post.rb | 4 ++++ 5 files changed, 31 insertions(+), 7 deletions(-) (limited to 'interfaces') diff --git a/interfaces/http/web/views/index.erb b/interfaces/http/web/views/index.erb index ee96a6c..657859b 100644 --- a/interfaces/http/web/views/index.erb +++ b/interfaces/http/web/views/index.erb @@ -1,7 +1,12 @@ <% for post in @posts %> -

<%= post.title %>

+

<%= post.title %>

-

<%= post.created_at.strftime('%e %b %Y') %>

+

+ by + <%= post.user.name || post.user.username %> + on + <%= post.created_at.strftime('%e %b %Y') %> +

<%= post.body %> diff --git a/interfaces/http/web/views/not_found.erb b/interfaces/http/web/views/not_found.erb index 7a4228b..71912b3 100644 --- a/interfaces/http/web/views/not_found.erb +++ b/interfaces/http/web/views/not_found.erb @@ -1,3 +1,3 @@ -

404 Not Found

+

404 Not Found

The page you are looking for does not exist.

Go to front page.

diff --git a/interfaces/http/web/views/post.erb b/interfaces/http/web/views/post.erb index 1fe689a..21794fb 100644 --- a/interfaces/http/web/views/post.erb +++ b/interfaces/http/web/views/post.erb @@ -1,7 +1,12 @@

<%= @post.title %>

-

<%= @post.created_at %>

+

+ by + <%= @post.user.name || @post.user.username %> + on + <%= @post.created_at.strftime('%e %b %Y') %> +

<%= @post.body %> -
+
\ No newline at end of file diff --git a/interfaces/ruby/models/config.rb b/interfaces/ruby/models/config.rb index 55b4106..007dbb3 100644 --- a/interfaces/ruby/models/config.rb +++ b/interfaces/ruby/models/config.rb @@ -1,17 +1,27 @@ class Config < ActiveRecord::Base self.table_name = 'config' + before_validation :normalize_url + validates_presence_of :url validates_presence_of :title validates_presence_of :timezone - validates_presence_of :postsperpage + validates_presence_of :posts_per_page + +private + + def normalize_url + url.strip! + url.sub! /\/$/, '' + end end class CreateConfigTable < ActiveRecord::Migration[6.0] def change create_table :config do |t| + t.string :url, null: false t.string :title, null: false t.string :subtitle t.string :timezone, null: false - t.integer :postsperpage, null: false + t.integer :posts_per_page, null: false, default: 15 end end end diff --git a/interfaces/ruby/models/post.rb b/interfaces/ruby/models/post.rb index 3a29a1c..28cc82c 100644 --- a/interfaces/ruby/models/post.rb +++ b/interfaces/ruby/models/post.rb @@ -6,6 +6,10 @@ class Post < ActiveRecord::Base validates_presence_of :slug validates_presence_of :title validates_presence_of :body + + def url + "#{$config.url}/#{created_at.strftime("%Y/%m/%d")}/#{slug}" + end end class CreatePostTable < ActiveRecord::Migration[6.0] -- cgit v1.2.3