diff options
author | John Ankarström <john@ankarstrom.se> | 2021-03-03 14:36:03 +0100 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-03-03 14:36:03 +0100 |
commit | 27067b4d8e5e854f16e3bdb08c2f63f4250632a8 (patch) | |
tree | 3221635a1fda3604da02548debfab19b96ddd50c /interfaces/ruby | |
parent | d40c681d2f9d56e01cd5f1ff3e586b79ea4397f9 (diff) | |
download | comb-27067b4d8e5e854f16e3bdb08c2f63f4250632a8.tar.gz |
Add 'url' field to config table
Diffstat (limited to 'interfaces/ruby')
-rw-r--r-- | interfaces/ruby/models/config.rb | 14 | ||||
-rw-r--r-- | interfaces/ruby/models/post.rb | 4 |
2 files changed, 16 insertions, 2 deletions
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] |