提前感谢您提供的任何帮助!
对于我的 Ruby on Rails 网站(1.8.7、2.3.15),我正在尝试从 MySQL 表中提取数据,但遇到了“未定义方法”错误。我使用此代码的目标是显示属于某个纬度和经度范围内的所有位置的文本列表。
生产日志:
ActionView::TemplateError (undefined method `each' for nil:NilClass) on line #31 of app/views/its/map.html.erb:
28: <!-- TestingLocations -->
29:
30: <ul id="locations">
31: <% for masterlocation in @nearbylocations %>
32: <li><%= masterlocation.nickname %></a></li>
33: <% end %>
34: </ul>
地图控制器:
def map
@its = Its.find(params[:id])
if @its.user_id == current_user.id
@locations = Location.find(:all, :conditions => ["its_id = ?", params[:id]], :order => "order_num asc")
@mapscount = Saved.count(:all, :conditions => ['its_id = ?', params[:id]])
#@date_filter = Date.civil(params[:date_filter].values_at(:year, :month, :day))
# debugger
respond_to do |format|
format.html # map.html.erb
format.xml { render :xml => @its }
end
else
redirect_to '/'
@nearbylocations = Masterlocation.find(:all, :conditions => ["latitude > 25 AND latitude < 30 AND longitude > -75 AND longitude < -70", params[:id]], :order => ['nickname asc'])
end
再次感谢您的帮助!