aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-03-03 14:36:03 +0100
committerJohn Ankarström <john@ankarstrom.se>2021-03-03 14:36:03 +0100
commit27067b4d8e5e854f16e3bdb08c2f63f4250632a8 (patch)
tree3221635a1fda3604da02548debfab19b96ddd50c
parentd40c681d2f9d56e01cd5f1ff3e586b79ea4397f9 (diff)
downloadcomb-27067b4d8e5e854f16e3bdb08c2f63f4250632a8.tar.gz
Add 'url' field to config table
-rw-r--r--interfaces/http/web/views/index.erb9
-rw-r--r--interfaces/http/web/views/not_found.erb2
-rw-r--r--interfaces/http/web/views/post.erb9
-rw-r--r--interfaces/ruby/models/config.rb14
-rw-r--r--interfaces/ruby/models/post.rb4
5 files changed, 31 insertions, 7 deletions
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 %>
- <h2><%= post.title %></h2>
+ <h2><a href="<%= post.url %>"><%= post.title %></a></h2>
<div class="meta">
- <p><%= post.created_at.strftime('%e %b %Y') %></p>
+ <p>
+ by
+ <%= post.user.name || post.user.username %>
+ on
+ <%= post.created_at.strftime('%e %b %Y') %>
+ </p>
</div>
<div class="content">
<%= 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 @@
-<h1>404 Not Found</h1>
+<h2>404 Not Found</h2>
<p>The page you are looking for does not exist.</p>
<p><a href="/">Go to front page</a>.</p>
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 @@
<h1><%= @post.title %></h1>
<div class="meta">
- <p><%= @post.created_at %></p>
+ <p>
+ by
+ <%= @post.user.name || @post.user.username %>
+ on
+ <%= @post.created_at.strftime('%e %b %Y') %>
+ </p>
</div>
<div class="content">
<%= @post.body %>
-</div>
+</div> \ 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]