app/controllers/properties_controller.rb
# Search in model by params from index 'properties#search'
Search in model by params from index 'properties#search'
Search in model by params from index ' properties#search '
def search
    @opt1 = Address.select('distinct country, administrative_area_level_1')
    @opt1_grouped = @opt1.each_with_object({}) do |f, options|
      (options[f.country] ||= []) << [f.administrative_area_level_1]
    end
    @opt2 = Address.select('distinct administrative_area_level_1, locality')
    @opt2_grouped = @opt2.each_with_object({}) do |f, options|
      (options[f.administrative_area_level_1] ||= []) << [f.locality]
    end
    country = params[:country] || nil
    administrative_area = params[:administrative_area] || nil
    locality = params[:locality] || nil
    property_type = params[:property_type] || nil
    @property = Property.joins(:address)
                        .where('country LIKE ?'\
							'and administrative_area_level_1 LIKE ?'\
							'and locality LIKE ?'\
							'and property_type LIKE ?',
                               "%#{country}%", "%#{administrative_area}%", "%#{locality}%", "%#{property_type}%")
                        .page(params[:page])
                        .order('created_at DESC')
    render action: 'index'
  end
def search @opt1 = Address . select ( 'distinct country, administrative_area_level_1' ) @opt1_grouped = @opt1 . each_with_object ( { } ) do | f , options | ( options [ f . country ] ||= [ ] ) << [ f . administrative_area_level_1 ] end @opt2 = Address . select ( 'distinct administrative_area_level_1, locality' ) @opt2_grouped = @opt2 . each_with_object ( { } ) do | f , options | ( options [ f . administrative_area_level_1 ] ||= [ ] ) << [ f . locality ] end country = params [ :country ] || nil administrative_area = params [ :administrative_area ] || nil locality = params [ :locality ] || nil property_type = params [ :property_type ] || nil @property = Property . joins ( :address ) . where ( 'country LIKE ?' 'and administrative_area_level_1 LIKE ?' 'and locality LIKE ?' 'and property_type LIKE ?' , "%#{country}%" , "%#{administrative_area}%" , "%#{locality}%" , "%#{property_type}%" ) . page ( params [ :page ] ) . order ( 'created_at DESC' ) render action : 'index' end
Search in model by params from index 'properties#search'
Search in model by params from index ' properties#search '
# Create grouped optrions for administrative_area select tag # Joining addresses table to properties table by a single associated model # for searching sorted with 'created_at'