anipendakur
anipendakur

Reputation: 95

Ruby On Rails - Access model from a different file

I have a model in my rails application which is

class Person < ActiveRecord::Base
..
end

I would like to access this model from a different ruby file for certain manipulations. This is to populate my db. Can somebody please tell me how to go about it?

I am new to ruby on rails and hence a trivial question. I tried including the model by using require or require relative but I get a LoadError

Upvotes: 1

Views: 428

Answers (1)

Tomdarkness
Tomdarkness

Reputation: 3820

If you use a rake task to populate/manipulate your database then you can solve this problem by making the task depend on the rails environment, this will set up everything you need to access the db:

task :my_task => :environment do
#do whatever with your models here
end

Upvotes: 2

Related Questions