aboutsummaryrefslogtreecommitdiff
path: root/interfaces/ruby/models
diff options
context:
space:
mode:
Diffstat (limited to 'interfaces/ruby/models')
-rw-r--r--interfaces/ruby/models/config.rb14
-rw-r--r--interfaces/ruby/models/post.rb4
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]