Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venjob_nth
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
3
Merge Requests
3
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
Ngô Trung Hưng
venjob_nth
Commits
f5cac550
Commit
f5cac550
authored
Sep 09, 2020
by
Ngô Trung Hưng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
validate params search
parent
56fa3250
Pipeline
#1086
failed with stages
in 0 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
24 additions
and
8 deletions
+24
-8
app/common/init_search.rb
+15
-0
app/controllers/home_controller.rb
+2
-1
app/controllers/search_controller.rb
+3
-2
app/forms/search.rb
+0
-1
app/views/home/index.html.erb
+1
-1
config/application.rb
+1
-1
lib/solr/searches/query.rb
+2
-2
No files found.
app/common/init_search.rb
0 → 100644
View file @
f5cac550
# frozen_string_literal: true
module
InitSearch
def
searches
Search
.
new
search_params
end
private
def
search_params
return
{}
if
params
[
:search
].
blank?
params
.
require
(
:search
).
permit
(
:keyword
,
:industry_id
,
:city_id
)
end
end
app/controllers/home_controller.rb
View file @
f5cac550
...
...
@@ -2,13 +2,14 @@
# Home page
class
HomeController
<
ApplicationController
include
InitSearch
def
index
@search
=
Search
.
new
@industries
=
Industry
.
order
(
name: :asc
)
@job_count
=
Job
.
count
@cities
=
City
.
all_cities
@lasted_jobs
=
Job
.
order
(
created_at: :desc
).
limit
(
Job
::
NUMBER_LASTED_JOB
)
@top_cities
=
City
.
top_cities
(
9
)
@top_industries
=
Industry
.
top_industries
(
9
)
@search
=
searches
end
end
app/controllers/search_controller.rb
View file @
f5cac550
class
SearchController
<
ApplicationController
before_action
:load_data_dropdown
before_action
:load_data_dropdown
,
only: :search
include
InitSearch
def
search
return
render
'error/internal_server_error'
if
params
[
:search
].
blank?
...
...
@@ -8,7 +9,7 @@ class SearchController < ApplicationController
@city
=
City
.
find_by
(
id:
params
[
:search
][
:city_id
])
@results
=
Searches
::
Query
.
new
.
search
(
params
)
return
render
'error/page_not_found'
if
params
[
:page
].
to_i
>
@results
.
total_pages
@search
=
Search
.
new
@search
=
searches
render
:result
end
...
...
app/forms/search.rb
View file @
f5cac550
...
...
@@ -2,7 +2,6 @@
class
Search
include
ActiveModel
::
Model
attr_accessor
:keyword
,
:industry_id
,
:city_id
selected_industry
=
@industry
.
blank?
?
'*'
:
@industry
.
id
...
...
app/views/home/index.html.erb
View file @
f5cac550
<%
provide
(
:title
,
"
#{
t
(
'title.home'
)
}
"
)
%>
<%=
render
'search/banner_and_search'
%>
<div
class=
"padding_index"
></div>
<%
unless
@job_count
.
nil
?
%>
<%
unless
@job_count
.
blank
?
%>
<div
class=
"box_text_five_jobs"
>
<span>
<%=
t
(
'pages.index.lasted_job'
)
%>
</span>
</div>
...
...
config/application.rb
View file @
f5cac550
...
...
@@ -12,7 +12,7 @@ module Venjob
config
.
load_defaults
5.2
config
.
exceptions_app
=
self
.
routes
config
.
autoload_paths
+=
Dir
[
Rails
.
root
.
join
(
'lib'
,
'{service,src}'
)]
config
.
eager_load_paths
+=
Dir
[
Rails
.
root
.
join
(
'lib'
,
'{business,solr}'
)]
config
.
eager_load_paths
+=
Dir
[
Rails
.
root
.
join
(
'lib'
,
'{business,solr
,user
}'
)]
# i18n
config
.
i18n
.
available_locales
=
[
:en
,
:vi
]
config
.
i18n
.
default_locale
=
:vi
...
...
lib/solr/searches/query.rb
View file @
f5cac550
# frozen_string_literal: true
module
Searches
class
Query
def
search
(
params
)
...
...
@@ -17,6 +15,8 @@ module Searches
def
sub_space_params!
(
keyword
,
industry_id
,
location_id
)
arr_params
=
{}
industry_id
=
''
if
Industry
.
find_by_id
(
industry_id
).
blank?
location_id
=
''
if
City
.
find_by_id
(
location_id
).
blank?
arr_params
[
:keyword
]
=
RSolr
.
solr_escape
(
keyword
.
downcase
||
''
)
arr_params
[
:industry_id
]
=
RSolr
.
solr_escape
(
industry_id
||
''
)
arr_params
[
:location_id
]
=
RSolr
.
solr_escape
(
location_id
||
''
)
...
...
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