I'm very new to Ruby. I have the following piece of code which is giving me an error.
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
The error being shown when I hit the url is NoMethodError in ItemsController#populate undefined method `lat=' for Lbs2 id: nil, body: nil, created_at: nil, updated_at: nil
This code worked perfectly without "if !Lbs2.find_by_body(ni.body)" statement. When I included this, in order to avoid the redundant news_items, it gave me the above mentioned error. Can someone please tell me how to get rid of this error at the same time avoiding redundant news_items from getting populated in Lbs2? Thanks in advance