ruby向数据库用语句插入数据
1.dos工程路径下执行(c:home/trunk/src下):
ruby script/generatemigration AddPermissionsData(名字随便起)
生成时间戳文件
class AddPermissionsData< ActiveRecord::Migration
def self.up
p = Permission.create({:name => ‘张三‘, :parent_id => ‘367‘, :deleted => ‘0‘, :action => ‘schedule‘, :sort_number => ‘4‘})
end
def self.down
end
end
执行 rake db:migrate
Ok…..
-------------------------------------------------------------------
2.在lib-tasks下新建data_update.rake里面代码
namespace :data_permissions do
//task名online_update随意起
task:online_update => :environment do
Model:Permission,向表Permissions插数据
p =Permission.create({:name => ‘张三‘, :parent_id => ‘367‘, :deleted=> ‘0‘, :action => ‘/schedule‘, :sort_number=> ‘4‘})
end
end
执行:rake 文件名:task名
rake data_permissions:online_update
成功!(版本低)
高版本用:rails g migration add_data_to_p
本文出自 “骑猴上树” 博客,请务必保留此出处http://qihoushangshu.blog.51cto.com/7872138/1409326