Forum: Ruby on Rails Insert using Rake Task

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Rake N. (Guest)
on 2009-03-05 09:11
Hi,

Anyone can help me, I run my source code using rake task. It seems no
error was trace, but when I look the table it doesn't insert.I select
the data here MysqlDB.Tablename and update/insert here
SQLserverDB.TableName.

# Start Here
# rake mysqldata_select:sqldata_update
def clean_html(html)
  new_html = strip_tags(html) # remove html tags
  new_html = decode_entities(new_html) # remove html encoded items
  new_html = new_html.strip # remove any whitespace from the edge of
content
end

namespace :mysqldata_select do

  LOCATIONS = {1 => 6, 2 => 5, 3 => 5}

  task :sqldata_update => :environment do
    include ActionView::Helpers::SanitizeHelper

    MysqlData::TableName.all(:conditions => {:field_id => [1,2,3]},
:order => :field_primary).each{ |j|
      r = TableName.new
      # place
      r.field = j.field_primary
      r.location_id = LOCATIONS[j.field_id]
      # save the item to get an ID
      r.save
      # find any translations
      attributes = {}
      %w{tc sc jp kr pt}.each{ |language|
        attributes[language] = {}
        field = j.field_primary(language, true)
        attributes[language]['field'] = field unless field.nil?
      }
      # insert the translations
      r.update_attributes(attributes)
      puts r.field
      # break
    }
  end
end
# End Here

Thanks in Advance
This topic is locked and can not be replied to.