參考:
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 之上构建...
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
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 ...
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 # ...
Larticles Laravel / Vue应用Laravel 5.5 API,它将API资源与Vue.js前端一起使用快速开始 # Install Dependenciescomposer install# Run Migrationsphp artisan migrate# Import Articlesphp artisan db:seed# Add ...
炒作 [| | | ] 一个使用进行对等文件共享(以及更多)的CLI。 安装 需要nodejs 14+ npm install -g @hyperspace/cli ... hyp seed {urls...} - Download and make hyper data available to the network. hyp u
-seed value seed a new sequence of pseudo-random numbers -size geometry width and height of image -stretch type render text with this font stretch -stroke color graphic primitive stroke color -...
var mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about' var root = new BIP84 . fromSeed ( mnemonic ) var child0 = root . deriveAccount ( 0 ) ...
If you have any difficulties using this component, suggestions, or compliments about this component, I would be glad to hear them! Please send an Email to wak@wakproductions.com. The more user ...
I can't say much more about it except for the fact that its fast and compact<END><br>51,chexer.zip As Jonathan wrote, "This is a tool I wrote to use in DevStudio to facilitate memory address ...
About the Cover xiii Preface xv Why This Book Is Important . . . . . . xvi What This Book Is About . . . . . . . . xvi What Prior Knowledge You Should Have . . . . . . . . xviii Reading Paths . ....