Rails は初めてで、Rails 2.3.14 サイトの問題を解決しようとしています。問題は、私が修正しようとしているこの店舗ロケーターが戻ってくることです
nil:NilClass の未定義のメソッド「coordinates」
距離パラメータ内に店舗が見つからない場合。見つかった場合は、正常に動作します。
コントローラーで作業しようとしている現在のコードは次のとおりです
@map = GMap.new("locations-gmap-div", "locationsGMap")
@map.control_init(:large_map => true, :map_type => true)
@mapp.center_zoom_init(@locations.first.coordinates, 8)
これが私のコードでやろうとしたことです。私はまだ Rails に非常に慣れていないので、ここでフィールドから外れていたら申し訳ありません。
@map = GMap.new("locations-gmap-div", "locationsGMap")
@map.control_init(:large_map => true, :map_type => true)
if @map.center_zoom_init(@locations.first.coordinates,8).nil?
flash[:error] = 'Sorry, we could not find any stores matching that criteria.'
redirect_to store_locator_path
else
@map.center_zoom_init(@locations.first.coordinates,8)
end
どんな助けでも大いに感謝します。