0
我写的一个实例如下当你没有想到它时,你有一个零对象!你可能会认为阵列
def search
cuisine=Settings.allcuisines
begin
@orgs = getSearch(params[:lat], params[:lon],params[:zip], params[:dist], cuisine,params[:num_results])
respond_to do |format|
format.html {render action: "index"}
format.json { render json: @orgs }
end
messg="success"
code="0"
results={:message=>messg,:code=>code}
resul=Results.new(results)
resul.save
rescue Exception => exc
messg=exc.message
code="1"
results={:message=>messg,:code=>code}
resul=Results.new(results)
resul.save
respond_to do |format|
format.html {render action: "index"}
format.json { render json: @orgs }
end
end
我得到错误:
You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each
这究竟是为什么?
实际的错误不在该代码中。无论是在它调用的方法还是在您的视图中。 – 2012-03-09 17:57:37
def getSearch(lat,lon,zip,dist,cuisine,num_results,unit =:mi) num_results || = 10 unit || =:mi if zip.strip.empty? Org.where('content.attribs.name'=>'cuisine','content.attribs.value'=>烹饪) .geo_near([lon,lat],::max_distance => dist,:spherical => true ,num:num_results) end if(lat.strip.empty?|| lon.strip.empty?) Zipcode.where('zipcode'=> zip) 方法如上,视图为<%for org in @机构单位%>
可以单击下面的 “编辑”你的问题添加额外的信息':)'。 – 2012-03-10 07:19:52
回答
您可能在您的视图中打电话@ orgs.each,@orgs为零。您可以尝试将您的迭代器嵌套在:
来源
2012-03-09 18:43:42
是我使用这样看来,<%为组织中@orgs%>
相关问题