site_blog 0.4.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf041277feab727166fd7043e16a4acabc3c76c2331ea3539e10b0d09e0d5379
4
- data.tar.gz: 92a866da471993311f3dfbdcbe65d799d2d3c4e79b3f1c402e0fe5fefc6f5507
3
+ metadata.gz: 06fc6ef0736ab3372d299ef20a35998019629c62043316a0a018f53d56da11bb
4
+ data.tar.gz: fe7218b9491eebb51a25e9903fa503c124a0116321477174feab66153093cc99
5
5
  SHA512:
6
- metadata.gz: 6b2a7822605383b579c46a204bdf88c00077365d9632606208d1174e5f810a8269e1bd573e8803dff2b26997138d5c65be71749f87e5d5873c536678628107a5
7
- data.tar.gz: 2c0a2e6a362662a95d5e4517029306bdebb56266a09accdd87b25d07101f57bde1dc6d7662129783d892584f231359304a75fa871bcffd776841caffaa1c9450
6
+ metadata.gz: 3d1a252fbf87b87056223cce8e7b0d234266e6ec788e91354daf6866202f034bd858588e05f373e5f3d13e4822537be77465a5257556f1228dfe040a3405ca06
7
+ data.tar.gz: 2eccec756cd91ce135fcb6479e1df0bcbb99a0a41f401986a505a8167c9fc79bac9dcf9684fc217fc1b41c8c9dd8a9593d3a36d5006a7cfa7755ec343801ed6b
@@ -47,7 +47,7 @@ module SiteBlog
47
47
 
48
48
  # Only allow a list of trusted parameters through.
49
49
  def tag_params
50
- params.require(:tag).permit(:title, :arichived)
50
+ params.require(:tag).permit(:slug, :arichived)
51
51
  end
52
52
  end
53
53
  end
@@ -13,12 +13,13 @@ module SiteBlog
13
13
 
14
14
  mount_uploader :image, SiteBlog::ImageUploader
15
15
 
16
- belongs_to :tag
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(tag_id: params[:tag_id]) if params[:tag_id].present?
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.order('created_at DESC').page(params[:page]).per(20)
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
@@ -1,5 +1,17 @@
1
1
  module SiteBlog
2
2
  class Tag < ApplicationRecord
3
- has_many :articles
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
@@ -0,0 +1,6 @@
1
+ module SiteBlog
2
+ class Tagging < ApplicationRecord
3
+ belongs_to :article
4
+ belongs_to :tag
5
+ end
6
+ 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 :title
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 :site_blog_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
@@ -1,3 +1,3 @@
1
1
  module SiteBlog
2
- VERSION = "0.4.0"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: site_blog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eldar
@@ -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,11 +158,11 @@ 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
150
165
  - db/migrate/20230201140930_add_article_and_tag.rb
151
- - db/migrate/20230221033922_remove_tables.rb
152
166
  - lib/site_blog.rb
153
167
  - lib/site_blog/engine.rb
154
168
  - lib/site_blog/version.rb
@@ -1,6 +0,0 @@
1
- class RemoveTables < ActiveRecord::Migration[7.0]
2
- def change
3
- drop_table :site_blog_tags
4
- drop_table :site_blog_articles
5
- end
6
- end