aboutsummaryrefslogtreecommitdiff
path: root/interfaces/ruby/models/config.rb
blob: 007dbb3b22e63432384facacd2cba8bba7ac5a50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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 :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 :posts_per_page, null: false, default: 15
    end
  end
end