私はデータベースをシードすることを知っています.rake db:seedとすべてを実行します。私は自分のseeds.rbファイルをすべてセットアップしました:
users = [{:name => 'User1 Lastname', :email => 'user1@example.com', :password => 'password'},
{:name => 'User2', :email => 'user2@example.com', :password => 'password'},
{:name => 'User3', :email => 'user3@example.com', :password => 'password'},
{:name => 'User4', :email => 'user4@example.com', :password => 'password'},
{:name => 'User5', :email => 'user5@example.com', :password => 'password'},
{:name => 'User6', :email => 'user6@example.com', :password => 'password'},
{:name => 'User7', :email => 'user7@example.com', :password => 'password'},
{:name => 'User8', :email => 'user8@example.com', :password => 'password'},
{:name => 'User9', :email => 'user9@example.com', :password => 'password'},
{:name => 'User10', :email => 'user10@example.com', :password => 'password'},
{:name => 'User11', :email => 'user11@example.com', :password => 'password'},
{:name => 'User12', :email => 'user12@example.com', :password => 'password'},
{:name => 'User13', :email => 'user13@example.com', :password => 'password'},
{:name => 'User14', :email => 'user14@example.com', :password => 'password'},
{:name => 'User15', :email => 'user15@example.com', :password => 'password'},
{:name => 'User16', :email => 'user16@example.com', :password => 'password'},
{:name => 'User17', :email => 'user17@example.com', :password => 'password'},
{:name => 'User18', :email => 'user18@example.com', :password => 'password'},
{:name => 'User19', :email => 'user19@example.com', :password => 'password'},
{:name => 'User20', :email => 'user20@example.com', :password => 'password'},
]
users.each do |user|
User.create(user)
end
しかし、今では実行rails server
するたびに、それらすべてに再びシードが付けられます! 私はそれが私が走ったときだけ起こるはずだと思ったrake db:seed
~$ rails server
=> Booting WEBrick
=> Rails 3.2.14 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Connecting to database specified by database.yml
(0.1ms) begin transaction
User Exists (21.5ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('user1@example.com') LIMIT 1
(0.1ms) rollback transaction
(0.1ms) begin transaction
User Exists (1.4ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('user2@example.com') LIMIT 1
(0.1ms) rollback transaction
(0.1ms) begin transaction
User Exists (1.3ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('user3@example.com') LIMIT 1
(0.1ms) rollback transaction
など 20 人のユーザーの場合は、それを起動します。
[2013-11-07 00:59:14] INFO WEBrick 1.3.1
[2013-11-07 00:59:14] INFO ruby 1.9.3 (2013-06-27) [i686-linux]
[2013-11-07 00:59:14] INFO WEBrick::HTTPServer#start: pid=1742 port=3000
どんな助けでも大歓迎です!! ありがとうございました