homeland-press 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30be3e204d09b92d87040eb9d2ae7761afbcdad7
|
4
|
+
data.tar.gz: df05927e51707cd6bbce8c83dc19a5917c995f50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cda7883c57d45ec8bdd9096cb282b9da3bf8c7adc2c3a884bbc4a36aa4cf00d0e56a37e83145782318f52452dc54a5543b014a8401be3b82ecc424160181845c
|
7
|
+
data.tar.gz: 41ee2131ca13e4c292253819b9a5b2513c91ed356328eec0f2c59b64b1c9da913fba38aa0a88e6818b174de85aed11317fdd6a6a54fe98b0a81e9a6434d9028d
|
data/app/models/post.rb
CHANGED
@@ -4,10 +4,14 @@ class Post < ApplicationRecord
|
|
4
4
|
|
5
5
|
enum status: %i(upcoming published rejected)
|
6
6
|
|
7
|
+
validates :slug, uniqueness: true, if: Proc.new { |post| post.slug.present? }
|
8
|
+
validates :title, :summary, :body, presence: true
|
9
|
+
|
7
10
|
counter :hits
|
8
11
|
|
9
12
|
before_save :generate_summary
|
10
13
|
before_create :generate_published_at
|
14
|
+
before_validation :safe_slug
|
11
15
|
|
12
16
|
def to_param
|
13
17
|
self.slug.blank? ? self.id : self.slug
|
@@ -33,6 +37,11 @@ class Post < ApplicationRecord
|
|
33
37
|
|
34
38
|
private
|
35
39
|
|
40
|
+
def safe_slug
|
41
|
+
self.slug.downcase!
|
42
|
+
self.slug.gsub!(/[^a-z0-9]/i, '-')
|
43
|
+
end
|
44
|
+
|
36
45
|
def generate_published_at
|
37
46
|
self.published_at = Time.now
|
38
47
|
end
|
@@ -12,7 +12,7 @@
|
|
12
12
|
<%= simple_format post.summary %>
|
13
13
|
</div>
|
14
14
|
<div class="post-info">
|
15
|
-
<%=
|
15
|
+
<%= press_user_name_tag(post.user) %> ·
|
16
16
|
<span class="time" title="发布时间"><i class="fa fa-clock-o"></i> <%= timeago(post.created_at) %></span> ·
|
17
17
|
<%= link_to "#{post.comments_count} 条评论", post_path(post, anchor: 'comments') %>
|
18
18
|
</div>
|
@@ -23,7 +23,7 @@
|
|
23
23
|
</div>
|
24
24
|
<h1><%= @post.title %></h1>
|
25
25
|
<div class="post-info">
|
26
|
-
<%=
|
26
|
+
<%= press_user_name_tag(@post.user) %> ·
|
27
27
|
<span class="time" title="发布时间"><i class="fa fa-clock-o"></i> <%= timeago @post.created_at %></span> ·
|
28
28
|
<%= @post.hits %> 次阅读 ·
|
29
29
|
<a href="#comments"><i class="fa fa-comments-o"></i> <%= @post.comments_count %> 条评论</a>
|
@@ -34,7 +34,9 @@
|
|
34
34
|
<div class="post-actions">
|
35
35
|
<%= likeable_tag(@post, class: 'btn btn-lg btn-default') %>
|
36
36
|
|
37
|
-
|
37
|
+
<% unless @post.user&.admin? %>
|
38
|
+
<%= reward_user_tag(@post.user, class: 'btn btn-lg btn-default') %>
|
39
|
+
<% end %>
|
38
40
|
</div>
|
39
41
|
</div>
|
40
42
|
</div>
|