create rake task

本文详细介绍了如何在Rails应用中使用Rake文件来更新现有的数据模型字段,包括字符编码检查和处理,以及如何操作大量数据记录。
1. rails g task my_namespace my_task1 my_task2
2. under lib/tasks/ folder, there will be file with the name of my_namespace.rake
3. coding in the rake file:

namespace :my_namespace do
desc "We need to update some fields in existing data model"
task my_task1: :environment do
##############################################
def check_char(str, n)
list_of_chars = str.unpack("U*")
char = list_of_chars[n]
#main blocks
if char >= 0x4E00 && char <= 0x9FFF
return true
end
#extended block A
if char >= 0x3400 && char <= 0x4DBF
return true
end
#extended block B
if char >= 0x20000 && char <= 0x2A6DF
return true
end
#extended block C
if char >= 0x2A700 && char <= 0x2B73F
return true
end
#extended block D
if char >= 0x2B740 && char <= 0x2B81F
return true
end

return false
end
...
[b]data = Model.all[/b]
...
create create README.md create Rakefile create .ruby-version create config.ru create .gitignore create .gitattributes create Gemfile run git init && git symbolic-ref HEAD refs/heads/main from "." Initialized empty Git repository in D:/1111/blog/.git/ create app create app/assets/stylesheets/application.css create app/controllers/application_controller.rb create app/helpers/application_helper.rb create app/jobs/application_job.rb create app/mailers/application_mailer.rb create app/models/application_record.rb create app/views/layouts/application.html.erb create app/views/layouts/mailer.html.erb create app/views/layouts/mailer.text.erb create app/views/pwa/manifest.json.erb create app/views/pwa/service-worker.js create app/assets/images create app/assets/images/.keep create app/controllers/concerns/.keep create app/models/concerns/.keep create bin create bin/brakeman create bin/bundler-audit create bin/ci create bin/dev create bin/rails create bin/rake create bin/rubocop create bin/setup create bin/thrust create Dockerfile create .dockerignore create bin/docker-entrypoint create .rubocop.yml create .github/workflows create .github/workflows/ci.yml create .github/dependabot.yml create config create config/routes.rb create config/application.rb create config/environment.rb create config/bundler-audit.yml create config/cable.yml create config/ci.rb create config/puma.rb create config/storage.yml create config/environments create config/environments/development.rb create config/environments/production.rb create config/environments/test.rb create config/initializers create config/initializers/assets.rb create config/initializers/content_security_policy.rb create config/initializers/cors.rb create config/initializers/filter_parameter_logging.rb create config/initializers/inflections.rb create config/initializers/new_framework_defaults_8_1.rb create config/locales create config/locales/en.yml create config/master.key append .gitignore create config/boot.rb create config/database.yml create db create db/seeds.rb create lib create lib/tasks create lib/tasks/.keep create log create log/.keep create public create public/400.html create public/404.html create public/406-unsupported-browser.html create public/422.html create public/500.html create public/icon.png create public/icon.svg create public/robots.txt create script create script/.keep create tmp create tmp/.keep create tmp/pids create tmp/pids/.keep create vendor create vendor/.keep create test/fixtures/files create test/fixtures/files/.keep create test/controllers create test/controllers/.keep create test/mailers create test/mailers/.keep create test/models create test/models/.keep create test/helpers create test/helpers/.keep create test/integration create test/integration/.keep create test/test_helper.rb create test/system create test/system/.keep create test/application_system_test_case.rb create storage create storage/.keep create tmp/storage create tmp/storage/.keep remove config/initializers/cors.rb remove config/initializers/new_framework_defaults_8_1.rb run bundle install --quiet
11-12
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值