diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/blog.rb | 2 | ||||
-rw-r--r-- | app/models/quote.rb | 9 | ||||
-rw-r--r-- | app/models/stream.rb | 11 | ||||
-rw-r--r-- | app/models/update.rb | 8 |
4 files changed, 29 insertions, 1 deletions
diff --git a/app/models/blog.rb b/app/models/blog.rb index db05432..03c0619 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb | |||
@@ -15,7 +15,7 @@ class Blog < ApplicationRecord | |||
15 | validates :body, presence: true, if: :published | 15 | validates :body, presence: true, if: :published |
16 | validates :slug, presence: true, format: /\A[-a-z0-9]+\z/, if: :published | 16 | validates :slug, presence: true, format: /\A[-a-z0-9]+\z/, if: :published |
17 | validates :user, presence: true | 17 | validates :user, presence: true |
18 | validates :images, content_type: ['image/png', 'image/jpeg'] | 18 | validates :images, content_type: ['image/png', 'image/jpeg', 'video/mp4', 'image/gif'] |
19 | 19 | ||
20 | before_validation :set_draft_title | 20 | before_validation :set_draft_title |
21 | before_save :set_published_at | 21 | before_save :set_published_at |
diff --git a/app/models/quote.rb b/app/models/quote.rb index 3301667..b1d25b4 100644 --- a/app/models/quote.rb +++ b/app/models/quote.rb | |||
@@ -36,4 +36,13 @@ class Quote < ApplicationRecord | |||
36 | def has_tags? | 36 | def has_tags? |
37 | !tags.empty? | 37 | !tags.empty? |
38 | end | 38 | end |
39 | |||
40 | def self.ransackable_attributes(auth_object = nil) | ||
41 | ["content", "notes"] | ||
42 | end | ||
43 | |||
44 | def self.ransackable_associations(auth_object = nil) | ||
45 | [] | ||
46 | end | ||
47 | |||
39 | end | 48 | end |
diff --git a/app/models/stream.rb b/app/models/stream.rb index 0773143..6a738e2 100644 --- a/app/models/stream.rb +++ b/app/models/stream.rb | |||
@@ -8,11 +8,22 @@ class Stream < ApplicationRecord | |||
8 | validates :title, presence: true | 8 | validates :title, presence: true |
9 | validates :slug, presence: true, format: /\A[-a-z0-9]+\z/ | 9 | validates :slug, presence: true, format: /\A[-a-z0-9]+\z/ |
10 | 10 | ||
11 | before_create :set_post_timestamp | ||
12 | |||
11 | def path | 13 | def path |
12 | "/thinks/#{slug}" | 14 | "/thinks/#{slug}" |
13 | end | 15 | end |
14 | 16 | ||
17 | def to_param | ||
18 | slug | ||
19 | end | ||
20 | |||
15 | def taggable | 21 | def taggable |
16 | self | 22 | self |
17 | end | 23 | end |
24 | |||
25 | private | ||
26 | def set_post_timestamp | ||
27 | self.latest_post_at = self.created_at | ||
28 | end | ||
18 | end | 29 | end |
diff --git a/app/models/update.rb b/app/models/update.rb index 01907d8..a98a5d4 100644 --- a/app/models/update.rb +++ b/app/models/update.rb | |||
@@ -5,6 +5,8 @@ class Update < ApplicationRecord | |||
5 | 5 | ||
6 | validates :stream, :body, presence: true | 6 | validates :stream, :body, presence: true |
7 | 7 | ||
8 | after_create :set_latest_timestamp | ||
9 | |||
8 | def path | 10 | def path |
9 | "/thinks/#{stream.slug}\#update-#{id}" | 11 | "/thinks/#{stream.slug}\#update-#{id}" |
10 | end | 12 | end |
@@ -12,4 +14,10 @@ class Update < ApplicationRecord | |||
12 | def taggable | 14 | def taggable |
13 | stream | 15 | stream |
14 | end | 16 | end |
17 | |||
18 | private | ||
19 | def set_latest_timestamp | ||
20 | self.stream.latest_post_at = self.created_at | ||
21 | self.stream.save! | ||
22 | end | ||
15 | end | 23 | end |