參考:
http://rails-bestpractices.com/posts/20-isolating-seed-data
先看一段代碼...
class CreateRoles < ActiveRecord::Migration
def self.up
create_table :roles, :force => true do |t|
t.string :name
t.timestamps
end
["admin", "author", "editor", "account"].each do |name|
Role.create!(:name => name)
end
end
def self.down
drop_table :roles
end
end
這個東東不陌生吧...所以不解析了..
現在讓我們用兩種方法來改良下吧:
(1)添加rake任務來處理:
#lib\tasks\dev.rake(這是rails2.3.4之前的做法)
namespace :dev do
desc "Setup seed data"
task :setup => :environment do
["admin", "author", "editor", "account"].each do |name|
Role.create!(:name => name)
end
end
end
如果不知道上面任務是啥意思,可參考:
rake任務詳解
http://fireflyman.iteye.com/blog/719362
既然上面強調了2.3.4,那下面當然是2.3.4的做法了..
#db\seed.rb
["admin", "author", "editor", "account"].each do |name|
Role.create!(:name => name)
end
詳細參考下面:
Rails 2.3.4 发布!
http://www.iteye.com/news/10161-rails-ruby
增加了新功能-->
引用
加入了db/seeds.rb作为默认文件,往数据库中保存seed信息.可以通过rake db:seed使用.
試了下...效果如下:
分享到:
相关推荐
Starting off with the fundamental command-line tools, you will learn about the Ansible tool. You will explore how to build hosts automatically and interactive pre-seed. You will also delve into the ...
## About该项目通过添加来提供OAuth2流,从而在项目的基础上进行构建。 ##指导 ####安装 $ npm install $ npm i -g mocha $ node app.js --development ####测试有关示例测试,请参见testing/userTests.js 。...
例如 py ElectrumSeedLister.py abandon ability able about above absent absorb gronk absurd abuse access accident不在英语单词列表中的单词将用单词列表中的单词替换。 将产生以下输出: Not in word list: ...
介绍 Angular 2应用程序的种子项目。 它类似于AngularJS快速入门,但是使用gulp进行了整个构建。 注意: Angular 2.0尚未准备好生产...├── app│ ├── components│ │ ├── about│ │ │ ├── about.h
介绍 Angular 2应用程序的种子项目。 它类似于AngularJS快速入门,但是使用gulp进行了整个构建。 注意: Angular 2.0尚未准备好生产! 这个种子项目非常适合使用最新版本,但不要使用...│ │ │ ├── about.h
##About 是一个功能齐全的 CRUD 应用程序。 这是一种利用 Java 的强大功能开始构建跨浏览器工作的 HTML 应用程序的方法。 它使用带有纯 Maven 配置的 Google Web Toolkit,适用于希望在 Google App Engine 之上构建...
13. seed - 种子 重点短语包括: 1. hear about sb/sth - 从某人那里听说某事 2. give sb a hug - 给某人一个拥抱 3. since then - 自从那时起 4. wait for sb anxiously - 焦急地等待某人 5. get lost - 迷路 6. ...
This paper adopts a semi-supervised method which is based on Bootstrapping to analyze Sina micro blog data which size is about 269M. The Support Vector Machine (SVM) method is used in ...
# If you get an error about an encryption key php artisan key:generate 终点 列出所有带有链接和元的文章 GET api/articles 获得单篇文章 GET api/article/{id} 删除文章 DELETE api/article/{id} 添加文章 POST...
He has developed numerous such projects, including AngularJS 1.x and Angular 2 style guides, angular2-seed, a static code analyzer for Angular 2 projects, aspect.js, angular-aop, and many others....
单页应用程序 Javascript 单页应用程序是使用 JavaScript/Express/Node.js 构建的 * To run: $ npm install 所有 SPA 都使用 sqlite3 持久化,并且客户端 AJAX 调用被发送到服务器。...$ node seed.js
学习了如何种植植物("plant a plant")和播种("plant a seed"),制作海报("make a poster")以及表达愿望和请求的方式,如"Would you please (not) do sth?"。借贷和保持物品的动词短语有"lend sb sth", "borrow...
ng the rapid advancement of Artificial Intelligence (AI), has transformed various industries and brought about new challenges, particularly in the realm of ethics. This working paper, "Ethical AI ...
Some suggestions about the establishment and management ofseed orchards in China were discussed, and the developmental programme of Xingcheng seed orchard of Pinus tabujgeformis Qarr,,Liaoning ...
16. He wrote a report about agriculture. 17. Alice sent some pictures to her parents. 四、完形填空部分(未提供具体内容,故无法提供答案)。 五、文章摘录: 这则老话说:“花时间停下来闻闻花香。”我认为...
seed = 11287 # use this if no value for seed on command line population_size = 100 max_depth_for_new_trees = 6 max_depth_after_crossover = 17 max_mutant_depth = 4 grow_method = RAMPED # ...
If we plant a good seed, we will get a good harvest." 这句话中,"the"的位置应填入不定冠词"a",因为"position"在此处是指一个抽象的、泛指的"小镇"的位置,而非特指某个特定的小镇。不定冠词"a"用于单数可数...
其中,`setup_train_args()`设置训练参数,`set_random_seed()`确保可复现性,`create_logger()`创建日志记录器,`create_model()`构建模型实例。`preprocess_raw_data()`和`preprocess_mmi_raw_data()`分别处理原始...