如何根据搜索参数进行json响应

时间:2016-04-12 09:47:12

标签: ruby-on-rails json ruby-on-rails-3 getjson

我希望根据过滤器得到json的共鸣。 现在在页面加载时,我正在获得该页面中列出的每个属性的json响应。 在同一页面我有过滤器,所以如果我根据json响应搜索属性通过过滤器应该改变。

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 

我的代码出了什么问题。 请帮忙 。 任何帮助都是值得赞赏的

0 个答案:

没有答案