`

create rake task

    博客分类:
  • RoR
 
阅读更多
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]
...
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics