Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
VietTH-VenShop
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tran Hoang Viet
VietTH-VenShop
Commits
00eca6c2
Commit
00eca6c2
authored
Jul 08, 2015
by
Tran Hoang Viet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
VietTH: Implement sorl callback to product
parent
389b2433
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
4 deletions
+19
-4
app/models/concerns/solr.rb
+18
-3
app/models/product.rb
+1
-1
No files found.
app/models/solr.rb
→
app/models/
concerns/
solr.rb
View file @
00eca6c2
module
Solr
extend
ActiveSupport
::
Concern
included
do
after_save
:push_data_to_solr
after_destroy
:remove_from_solr
# callbacks
def
push_data_to_solr
self
.
class
.
rsolr
.
add
(
self
.
slice
(
*
self
.
class
.
solr_fields
))
self
.
class
.
rsolr
.
commit
end
def
remove_from_solr
self
.
class
.
rsolr
.
delete_by_id
(
self
[
self
.
class
.
primary_key
])
self
.
class
.
rsolr
.
commit
end
end
module
ClassMethods
attr_accessor
:solr_per_page
,
:solr_page
,
:solr_total_count
attr_accessor
:solr_per_page
,
:solr_page
,
:solr_total_count
,
:solr_fields
def
solr_options
(
fields
=
{})
@solr_per_page
=
fields
[
:per_page
]
||
5
@solr_fields
=
fields
[
:fields
]
||
[]
end
def
search
(
query
,
options
=
{})
...
...
@@ -34,6 +51,5 @@ module Solr extend ActiveSupport::Concern
def
kaminari_paginate
Kaminari
.
paginate_array
([],
total_count:
solr_total_count
).
page
(
solr_page
).
per
(
solr_per_page
)
end
end
end
\ No newline at end of file
app/models/product.rb
View file @
00eca6c2
...
...
@@ -17,5 +17,5 @@ class Product < ActiveRecord::Base
mount_uploader
:image
,
ImageUploader
solr_options
per_page:
2
solr_options
per_page:
2
,
fields:
[
:id
,
:title
]
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment