2009-12-22 59 views
2

我正在关注本教程:http://friendlyorm.com/开始使用Friendly ORM

我正在使用InstantRails在本地运行MySQL。为了运行Ruby和Rails,我使用了普通的Windows安装。

当我运行Friendly.create_tables!时,我只得到一个返回的空数组:=> []并且没有表在我的'friendly_development'数据库中创建。

回答

1

作者友好在这里。

在调用Friendly.create_tables之前,您必须要求所有模型!否则,友方无法知道哪些型号存在。在未来的版本中,我会自动预装所有模型。

+0

我该怎么做? 要求'CamelCasedModelName'? – user94154 2009-12-23 23:49:32

+0

需要'the_name_of_the_file_that_contains_my_model' – 2009-12-24 00:58:19

+0

非常感谢。我很感激。 – user94154 2009-12-24 14:56:55

0

这里没多少东西。我的猜测是,它无法找到您在路径中创建的模型文件?

+0

我的模型被称为BlogPost,它位于app/models/blog_post.rb中。 你用过友善吗? – user94154 2009-12-22 20:31:53

1

我有一个耙子任务,在一个名叫Sutto的人的帮助下,将加载你的所有模型,然后调用Friendly.create_tables!并打印出涉及的所有表格。

namespace :friends do 
    desc "load in all the models and create the tables" 
    task :create => :environment do 
    puts "-----------------------------------------------" 
    Dir[Rails.root.join("app", "models", "*.rb")].each { |f|File.basename(f, ".rb").classify.constantize } 
    tables = Friendly.create_tables! 
    tables.each do |table| 
     puts "Table '#{table}'" 
    end 
    puts "-----------------------------------------------" 
    end 
end 

rake friends:create