我對Ruby非常陌生。我有以下代碼給我一個錯誤。Ruby腳本中的調試錯誤
class ItemsController < ApplicationController
def populate
Location.all.each { |l|
place = l.radar_place
next if !place
news_items = place.radars
news_items.each { |ni|
t = Lbs2.new
t.lat = l.lat
t.lng = l.lng
t.body = ni.body
t.save if !Lbs2.find_by_body(ni.body) #avoiding redundant news_items
}
}
render :text => "Success"
end
end
被示出的錯誤時,我打的網址是 NoMethodError在上述ItemsController#填充 未定義的方法`LAT =」爲LBS2 ID:無,體:無,created_at:無,的updated_at:無
這段代碼在沒有「if!Lbs2.find_by_body(ni.body)」語句的情況下工作得很完美。當我包括這個,爲了避免多餘的news_items,它給了我上面提到的錯誤。有人可以告訴我如何擺脫這個錯誤,同時避免冗餘news_items在Lbs2中填充?在此先感謝
它沒有工作,當我更換LBS2用t。 Lbs2是創建用於存儲lat,lng和body的模型。你能否建議一些其他的改變? – mamatha 2010-03-02 16:14:49
我認爲Lbs2有一個「拉特」列? – Shadowfirebird 2010-03-02 17:02:54
您可能還想標記這個問題「rails」 – Shadowfirebird 2010-03-02 17:04:05