site_blog 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/site_blog/tags_controller.rb +1 -1
- data/app/models/site_blog/article.rb +8 -4
- data/app/models/site_blog/tag.rb +13 -1
- data/app/models/site_blog/tagging.rb +6 -0
- data/db/migrate/20230201140930_add_article_and_tag.rb +8 -2
- data/lib/site_blog/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17c4d73ad52870e304479caf1049e94b12b4481e4c8d5eabb5bea12677c9097f
|
4
|
+
data.tar.gz: e72cc5aeba1c9a71b12559872ddc35afb984811f52284e8522a2907501976d8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d248b7747eeef9a2014adf611c15f014f13c1977603c3f8b0b076a62feb7afc767457829d971b60bef60ddc55943784382877ac88be25d4fab736c7057c0f56
|
7
|
+
data.tar.gz: d21079c4a65041f5c65c7b86e33d590e2003dbffd6337b5a250a5608be9eb15a793ccb83b76da41b1f44cd4a61f25c4ccb8669cb6c3f289cc2ec6573a1508982
|
@@ -13,12 +13,13 @@ module SiteBlog
|
|
13
13
|
|
14
14
|
mount_uploader :image, SiteBlog::ImageUploader
|
15
15
|
|
16
|
-
|
16
|
+
has_many :taggings, class_name: 'SiteBlog::Tagging'
|
17
|
+
has_many :tags, through: :taggings
|
17
18
|
|
19
|
+
validates :tags, presence: true
|
18
20
|
validates :title, presence: true, length: { minimum: 2 , maximum: 250 }
|
19
21
|
validates :description, presence: true
|
20
22
|
validates :image, presence: true
|
21
|
-
validates :tag_id, presence: true
|
22
23
|
validates :slug, presence: true, uniqueness: true, format: { with: /\A[a-z0-9\-_]+\z/ }
|
23
24
|
validates :locale, presence: true
|
24
25
|
|
@@ -28,9 +29,12 @@ module SiteBlog
|
|
28
29
|
|
29
30
|
scope :filters, lambda { |params|
|
30
31
|
rel = where(archived: false)
|
31
|
-
rel = rel.where(
|
32
|
+
rel = rel.joins(:tags).where(tags: { id: params[:tag_id] }) if params[:tag_id].present?
|
32
33
|
rel = rel.search(params[:query]) if params[:query].present?
|
33
|
-
rel.
|
34
|
+
rel = rel.where(main: true) if params[:main] == 'true'
|
35
|
+
rel = rel.order('created_at DESC')
|
36
|
+
rel = rel.limit(params[:limit]) if params[:limit]
|
37
|
+
rel = rel.page(params[:page]).per(20)
|
34
38
|
}
|
35
39
|
|
36
40
|
private
|
data/app/models/site_blog/tag.rb
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
module SiteBlog
|
2
2
|
class Tag < ApplicationRecord
|
3
|
-
has_many :
|
3
|
+
has_many :taggings, class_name: 'SiteBlog::Tagging'
|
4
|
+
has_many :articles, through: :taggings
|
5
|
+
|
6
|
+
validates :slug, presence: true
|
7
|
+
|
8
|
+
before_validation :slug_downcase
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def slug_downcase
|
13
|
+
self.slug = self.slug.downcase if self.slug.present?
|
14
|
+
end
|
15
|
+
|
4
16
|
end
|
5
17
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class AddArticleAndTag < ActiveRecord::Migration[7.0]
|
2
2
|
def change
|
3
3
|
create_table :site_blog_tags do |t|
|
4
|
-
t.string :
|
4
|
+
t.string :slug
|
5
5
|
t.boolean :archived, null: false, default: false
|
6
6
|
t.timestamps
|
7
7
|
end
|
@@ -12,14 +12,20 @@ class AddArticleAndTag < ActiveRecord::Migration[7.0]
|
|
12
12
|
t.text :html_description, null: false
|
13
13
|
t.text :description, null: false
|
14
14
|
t.string :image, null: false
|
15
|
-
t.belongs_to :tag, null: false, foreign_key: { to_table: :site_blog_tags }
|
16
15
|
t.integer :view_count, null: false, default: 0
|
17
16
|
t.boolean :archived, null: false, default: false
|
18
17
|
t.boolean :active, null: false, default: true
|
18
|
+
t.boolean :main, null: false, default: false
|
19
19
|
t.string :locale, null: false
|
20
20
|
t.timestamps
|
21
21
|
end
|
22
22
|
|
23
|
+
create_table :taggings do |t|
|
24
|
+
t.belongs_to :article, foreign_key: { to_table: :site_blog_articles }
|
25
|
+
t.belongs_to :tag, foreign_key: { to_table: :site_blog_tags }
|
26
|
+
t.timestamps
|
27
|
+
end
|
28
|
+
|
23
29
|
add_index :site_blog_articles, :slug, unique: true
|
24
30
|
end
|
25
31
|
end
|
data/lib/site_blog/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: site_blog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eldar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: activeadmin_addons
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description: Description of AppComponent
|
112
126
|
email:
|
113
127
|
- eldarweb@mail.ru
|
@@ -144,6 +158,7 @@ files:
|
|
144
158
|
- app/models/site_blog/application_record.rb
|
145
159
|
- app/models/site_blog/article.rb
|
146
160
|
- app/models/site_blog/tag.rb
|
161
|
+
- app/models/site_blog/tagging.rb
|
147
162
|
- app/uploaders/site_blog/image_uploader.rb
|
148
163
|
- app/views/layouts/blog/application.html.erb
|
149
164
|
- config/routes.rb
|