mardi 12 avril 2016

How to json response according to search params

i want to get json resonse according to filters. Now on page load i'm getting json response for the every properties which are listed in that page. In the same page i have filters ,so if i search property through filters according to that json response should change.

class PropertiesController < ApplicationController
  def index
    if params[:city].present?
       @properties=Property.where("properties.city = ? ",params[:city],"%#{params[:city]}%")
    elsif params[:cityname].present?
       @properties=Property.where("properties.city = ? ",params[:cityname])
    else
      @properties = Property.where("properties.status = ?", '1')
   end
      respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @properties.as_json(only: [:id, :latitude, :longitude]) }
    end
  end
  end 

What is wrong with my code. Please Help . Any help is appreciatable

Aucun commentaire:

Enregistrer un commentaire