# Insert using Rake Task

**URL:** <https://www.ruby-forum.com/t/insert-using-rake-task/162045>\
**Category:** Rails\
**Created:** [March 5, 2009, 8:11am UTC](https://www.ruby-forum.com/t/insert-using-rake-task/162045 "2009-03-05T08:11:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rakenewuser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e480ec/32.png) [@rakenewuser](https://www.ruby-forum.com/u/rakenewuser)\
**Post date:** [March 5, 2009, 8:11am UTC](https://www.ruby-forum.com/t/insert-using-rake-task/162045/1 "2009-03-05T08:11:31Z")

</div>

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
