Hi there! Im new on ruby/rails, and im tying to run the rake task below but I got an error. After I tested on script/console and I got the same error. Could you helpe me, please? Thanks! Pedro Rake Task: namespace :meuApp do desc ''Update geotable with longitude and latitude information'' task :add_geotable_coordinates => :environment do include GeoKit::Geocoders geotable = Geotable.find_by_sql(["SELECT * FROM geotable WHERE ADDRESS IS NOT NULL"]) begin geotable.each { |geotable| loc = MultiGeocoder.geocode(geotable.address) geotable.lat = loc.lat geotable.lng = loc.lng geotable.update puts "updated cartcid #{geotable.NOME} #{geotable.address} => [#{loc.lat}, #{loc.lng}]" } rescue puts $! end end end The script/console test:>>Geotable.find_by_sql(["SELECT * FROM geotable WHERE ADDRESS IS NOTNULL"]) .... .... data retrieved ommited ......>> @geotable.addressNoMethodError: undefined method `address'' for #<Array:0x4712fa0> from (irb):27 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You''re re-using your geotable variable inappropriately... try: geotables = Geotable.find_by_sql(["SELECT * FROM geotable WHERE ADDRESS IS NOT NULL"]) begin geotables.each { |geotable| loc = MultiGeocoder.geocode(geotable.address) blah blah blah -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Oct 1, 2010 at 12:58 PM, Pedro <pogermano-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi there! > Im new on ruby/rails, and im tying to run the rake task below but I > got an error. After I tested on script/console and I got the same > error. Could you helpe me, please? > > Thanks! > Pedro > > > > Rake Task: > > namespace :meuApp do > desc ''Update geotable with longitude and latitude information'' > task :add_geotable_coordinates => :environment do > include GeoKit::Geocoders > geotable = Geotable.find_by_sql(["SELECT * FROM geotable WHERE > ADDRESS IS NOT NULL"]) > begin > geotable.each { |geotable| >the collection and the object are named the same? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi radhames, Yes, the names were the same. Now I changed the names for table, collection, etc. Now, Im getting different error: undefined method `address'' for #<Array:0x4453c68> ++------------------------------------- new code----------------------------------++ namespace :Geo do desc ''Update cartcid with longitude and latitude information'' task :add_cartcid_coordinates => :environment do include GeoKit::Geocoders c = Cartcid.find_by_sql(["SELECT address FROM cartcid WHERE ADDRESS IS NOT NULL"]) begin c.each { |cartcid| loc = MultiGeocoder.geocode(c.address) c.lat = loc.lat c.lng = loc.lng c.update puts "updated cartcid #{c.nome} #{c.address} => [#{loc.lat}, #{loc.lng}]" } rescue puts $! end end end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Fri, Oct 1, 2010 at 2:23 PM, Pedro <pogermano-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi radhames, > > Yes, the names were the same. Now I changed the names for table, > collection, etc. Now, Im getting different error: undefined method > `address'' for #<Array:0x4453c68> > >Sometimes this happens when the class can ot be instanciated, see if you have a typo in the model somewhere -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> namespace :Geo do > desc ''Update cartcid with longitude and latitude information'' > task :add_cartcid_coordinates => :environment do > include GeoKit::Geocoders > c = Cartcid.find_by_sql(["SELECT address FROM cartcid WHERE > ADDRESS IS NOT NULL"]) > begin > c.each { |cartcid| > loc = MultiGeocoder.geocode(c.address) > c.lat = loc.lat > c.lng = loc.lng > c.update > puts "updated cartcid #{c.nome} #{c.address} => > [#{loc.lat}, #{loc.lng}]" > } > rescue > puts $! > end > end > endStill wrong... you did the exact same thing as before in another way...> c = Cartcid.find_by_sql(["SELECT address FROM cartcid WHEREGiven your code, "c" is an array (of Cardcid''s) - and the Array class does not have an address attribute.> c.each { |cartcid|Given this line, you are processing each individual element in "c" in a variable named "cartcid"> loc = MultiGeocoder.geocode(c.address)Now you are referencing the array "c" again!!! Just like you were doing in your earlier post. That line needs to be: loc = MultiGeocoder.geocode(cartcid.address) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ok, now I got it, the code is below, but now I have the follow error: Attempt to call private method I dont know if it is related with this error, but this table is a legacy and I had to set table name and primary key. The model is : class Cartcid < ActiveRecord::Base set_table_name "cartcid" set_primary_key "NUMERO" end namespace :GeoFind do desc ''Update cartcid with longitude and latitude information'' task :add_cartcid_coordinates => :environment do include GeoKit::Geocoders c = Cartcid.find_by_sql(["SELECT address, lat, lng FROM cartcid WHERE ADDRESS IS NOT NULL"]) begin c.each { |cartcid| loc = MultiGeocoder.geocode(cartcid.address) cartcid.lat = loc.lat cartcid.lng = loc.lng cartcid.update puts "updated cartcid #{cartcid.nome} #{cartcid.address} => [#{loc.lat}, #{loc.lng}]" } rescue puts $! end end end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 1, 10:48 pm, Pedro <pogerm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ok, now I got it, the code is below, but now I have the follow error: > > Attempt to call private method > > I dont know if it is related with this error, but this table is a > legacy and I had to set table name and primary key. >update is a private method - you should be calling save (or save!) Fred> The model is : > class Cartcid < ActiveRecord::Base > set_table_name "cartcid" > set_primary_key "NUMERO" > end > > namespace :GeoFind do > desc ''Update cartcid with longitude and latitude information'' > task :add_cartcid_coordinates => :environment do > include GeoKit::Geocoders > c = Cartcid.find_by_sql(["SELECT address, lat, lng FROM > cartcid WHERE ADDRESS IS NOT NULL"]) > begin > c.each { |cartcid| > loc = MultiGeocoder.geocode(cartcid.address) > cartcid.lat = loc.lat > cartcid.lng = loc.lng > cartcid.update > puts "updated cartcid #{cartcid.nome} > #{cartcid.address} => > [#{loc.lat}, #{loc.lng}]" > } > rescue > puts $! > end > end > end-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 October 2010 22:48, Pedro <pogermano-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Attempt to call private methodWhere you got told about that error, you would''ve been told the line number... passing on that information would help in most cases (and would tell you *exactly* where the problem is)> cartcid.update"update" is a private method - you probably just want to .save -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
It is running, but not saving, is there a commit like command? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 1, 11:32 pm, Pedro <pogerm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> It is running, but not saving, is there a commit like command?No. The problem is that because you''ve only selected the address column rails can''t save the object, because it doesn''t know its id. Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
So, what I have to do? Use c =Cartcid.find(:all) instead? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 October 2010 23:42, Pedro <pogermano-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So, what I have to do? Use c =Cartcid.find(:all) instead?Firstly, please quote what you''re replying to, because your last two posts make no sense out of context.>On 1 October 2010 23:35, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> No. The problem is that because you''ve only selected the address >> column rails can''t save the object, because it doesn''t know its id.Secondly, what did you try in response to Fred pointing out you''d only selected the address? You could use .find(:all) (or .all) or you could "SELECT * ..." in your find_by_sql. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Fred post:::: On Oct 1, 11:32 pm, Pedro <pogerm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> It is running, but not saving, is there a commit like command?No. The problem is that because you''ve only selected the address column rails can''t save the object, because it doesn''t know its id. Fred Michael Pavlin post : On 1 October 2010 23:42, Pedro <pogerm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So, what I have to do? Use c =Cartcid.find(:all) instead?Firstly, please quote what you''re replying to, because your last two posts make no sense out of context.>On 1 October 2010 23:35, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> No. The problem is that because you''ve only selected the address >> column rails can''t save the object, because it doesn''t know its id.Secondly, what did you try in response to Fred pointing out you''d only selected the address? You could use .find(:all) (or .all) or you could "SELECT * ..." in your find_by_sql. Im using find_by_sql(["SELECT address, lat, lng FROM cartcid WHERE ADDRESS IS NOT NULL"]) because the table have 60.000 rows, with blob field. This choice was made thinking in performance issues. So "select" would improve performance. Now I include the primary key on select and it works. Thanks to all of you, Pedro -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.