Class: CreateKeyWordFilters
- Inherits:
-
ActiveRecord::Migration
- Object
- ActiveRecord::Migration
- CreateKeyWordFilters
- Defined in:
- lib/generators/key_word_filter_on/migration/templates/active_record/migration.rb
Class Method Summary collapse
Class Method Details
.down ⇒ Object
17 18 19 |
# File 'lib/generators/key_word_filter_on/migration/templates/active_record/migration.rb', line 17 def self.down drop_table :key_word_filters end |
.up ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/generators/key_word_filter_on/migration/templates/active_record/migration.rb', line 2 def self.up create_table :key_word_filters do |t| t.column :content, :string # 过滤内容 t.column :replace, :string # 替换字符 t. end # 初始化关键字数据信息 path = "#{Rails.root}/config/key_word_filters.da" File.open(path) do |file| #say "init key_word_datas" file.each_line{|line| FilterKeyWordOn::KeyWordFilter.create(:content => line.strip, :replace => "**") } #添加数据 end if File.exist?(path) end |