Reputation: 47
I am writing as below
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
I am getting error:
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
Why is this happening?
Upvotes: 0
Views: 2691
Reputation: 9529
You are probably calling @orgs.each in your view and @orgs is nil. You can try just nesting your iterator in an:
- unless @orgs.nil?
- @orgs.each do |o|
blah
Upvotes: 1