Topic: Debug the error in Ruby script

I'm very new to Ruby. In the below code Lbs2 is the model generated to store lat,lng and body.  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 = =
       t.lng = l.lng
       t.body = ni.body if !Lbs2.find_by_body(ni.body) #avoiding redundant news_items
render :text => "Success"

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

Re: Debug the error in Ruby script

This means is that the lbs2 model does not have a lat or lng attribute.
If you only need to store lat and lng temporarily, you can use this in your lbs2 model:

attr_accessor :lat, :lng

If you need it to be stored in the database then you need to add columns for lat and lng to your model.

Re: Debug the error in Ruby script

Thanks.The problem was that when I did a script/generate model Lbs2 lat:double lng:double body:text, the lat and lng fields were not getting saved in the schema.rb.  I changed double to float and the problem got resolved.