Try this after loading the date from the yml file into records :
class Question < ActiveRecord::Base
You can simply create a model for import only. You do not need to create app/models/question.rb . Just write the code in the import script.
UPDATE:
You can use the following function:
def create_class(class_name, superclass, &block) klass = Class.new superclass, &block Object.const_set class_name, klass end
a source
File.open("#{RAILS_ROOT}/db/fixtures/#{table_name}.yml", 'r') do |file| YAML::load(file).each do |record| model_name = table_name.singularize.camelize create_class(model_name, ActiveRecod::Base) do set_table_name table_name.to_sym end Kernel.const_get(model_name).create(record) end end
To use the connection directly, you can use the following:
ActiveRecord::Base.connection.execute("YOUR SQL CODE")
source share