wikimisu
unread,Jul 22, 2008, 1:29:50 PM7/22/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails Taiwan
各位大大,我是使用"Ruby on Rails網路應用程式開發與建置"的書籍來當作範例....
但是在建立資料庫的時候發生了一些問題,
在lib\tasks\db_setup.rake有下列程式:
env = ENV['RAILS_ENV'] || 'development'
database = "LunchBooks_#{env}"
user = "lunchuser_#{env[0..0]}"
def connect
ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:host => 'localhost',
:username => 'root',
:password => '1234',
:database => 'mysql'
)
end
task :db_setup do
ActiveRecord::Schema.define do
connect
begin
create_database database
rescue
end
execute "create user #{user}@localhost identified by 'ror'"
execute "grant all privileges on #{database}.* to
'#{user}'@'localhost'"
end
end
task :db_clean do
ActiveRecord::Schema.define do
connect
begin
execute "drop user '#{user}'@'localhost'"
rescue
end
drop_database database
end
end
接著下指令...
> rake environment RAILS_ENV=production db_setup
-- execute("create user lunchuser_p@localhost identified by 'ror'")
-> 0.3590s
-- execute("grant all privileges on LunchBooks_production.* to
'lunchuser_p'@'localhost'")
-> 0.0320s
也都可以執行…
可是再來我又打了
> rake db_setup
rake aborted!
uninitialized constant ActiveRecord
(See full trace by running task with --trace)
我也看過先前網友的意見,加上了 :environment,
但是還是不能執行,請問該如何解決呢??
謝謝!!