views:

213

answers:

3

I'm following this tutorial: http://friendlyorm.com/

I'm using InstantRails to run MySQL locally. To run Ruby and Rails, I'm using normal Windows installations.

When I run Friendly.create_tables! I only get an empty Array returned: => [] and no tables are created in my 'friendly_development' database.

Any help on this on one?

Thanks!

A: 

not much to go on here. My guess is that it can't find your model file that you are creating in the path?

Arthur Thomas
my model is called BlogPost which is in app/models/blog_post.rb.Have you used Friendly?
+1  A: 

Author of Friendly here.

You'll have to require all of your models before calling Friendly.create_tables! Otherwise, there's no way for Friendly to know which models exist. In a future revision, I'll automatically preload all your models.

James Golick
how do I do that?Require 'CamelCasedModelName'?
require 'the_name_of_the_file_that_contains_my_model'
James Golick
thanks a lot. i appreciate it.
+1  A: 

I have a rake task, with help from a guy called Sutto, that will load in all your models and then call Friendly.create_tables! and print out all the tables involved.

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
Joc