Commit f5cac550 by Ngô Trung Hưng

validate params search

parent 56fa3250
Pipeline #1086 failed with stages
in 0 seconds
# 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
......@@ -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
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
......
......@@ -2,7 +2,6 @@
class Search
include ActiveModel::Model
attr_accessor :keyword, :industry_id, :city_id
selected_industry = @industry.blank? ? '*' : @industry.id
......
<% 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>
......
......@@ -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
......
# 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 || '')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment