How can I access Active Record classes to create records from a module/class in the lib folder?RoR mySQL ErrorWhy do I get a “no listener” error when using Rails with Oracle?Best way to load module/class from lib folder in Rails 3?Unable to start Mongrel (or Passenger) on Debian due to mysql2 or mysql gemsPDFKit won't render with Ubuntu on railsPG::Error server closed the connection unexpectedlygetting ActiveRecord errors when using mongoid and Sql on Ironworker filesProblems with “rails server”ActiveRecord::ConnectionNotEstablished error when upgrading toActiveRecord::StatementInvalid: Mysql2::Error: Unknown collation: 'utf8_0900_ai_ci'

Is a switch from R to Python worth it?

Can you take actions after being healed at 0hp?

Can this rough design show the required message?

Is the first page of a novel really that important?

Vibration on the guitar when playing two strings

Write The Shortest Program to Calculate Height of a Binary Tree

How to call made-up data?

Why do proponents of guns oppose gun competency tests?

Is space radiation a risk for space film photography, and how is this prevented?

How to deploy a LSTM Model

If someone else uploads my GPL'd code to Github without my permission, is that a copyright violation?

Are valid inequalities worth the effort given modern solvers?

Getting Lost in the Caves of Chaos

Is there a way to say "double + any number" in German?

Why do my fried eggs start browning very fast?

A verb for when some rights are not violated?

probability of a coin to show head given a liar is saying its head

How does LIDAR avoid getting confused in an environment being scanned by hundreds of other LIDAR?

Make lens aperture in Tikz

How easy is it to get a gun illegally in the United States?

How can I perform a deterministic physics simulation?

Identify Batman without getting caught

Not been paid even after reminding the Treasurer; what should I do?

Writing computer program code for free in an interview?



How can I access Active Record classes to create records from a module/class in the lib folder?


RoR mySQL ErrorWhy do I get a “no listener” error when using Rails with Oracle?Best way to load module/class from lib folder in Rails 3?Unable to start Mongrel (or Passenger) on Debian due to mysql2 or mysql gemsPDFKit won't render with Ubuntu on railsPG::Error server closed the connection unexpectedlygetting ActiveRecord errors when using mongoid and Sql on Ironworker filesProblems with “rails server”ActiveRecord::ConnectionNotEstablished error when upgrading toActiveRecord::StatementInvalid: Mysql2::Error: Unknown collation: 'utf8_0900_ai_ci'






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a Rails 4.2 app. I want to create a script in the lib folder that I will use to create records in my database. So hypothetically:



lib/user_builder.rb



require 'rubygems'
require 'active_record'
require './app/models/application_record.rb'
require './app/models/client.rb'

module UserTheory
class UserBuilder
def initialize
user = User.find_or_initialize_by(id: 1)
user.name = 'Bob'
user.save
end
end
end


I required those files because I was getting NameErrors about those classes. Now I am getting another error:



/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/connection_pool.rb:570:in `retrieve_connection': No connection pool for User (ActiveRecord::ConnectionNotEstablished)



so clearly I am going about this the wrong way.










share|improve this question
























  • instead of putting it in lib, try a directory inside app/ such as app/services. Then you shouldn't need the requires and autoloading should work properly.

    – Scott Bartell
    Mar 27 at 5:26






  • 1





    Why aren't you just using the db/seeds.rb file?

    – Jon
    Mar 27 at 7:03











  • Actually, you can use rake tasks to do your case

    – IlyaOsotov
    Mar 27 at 9:00











  • db/seeds.rb is the way to go here.

    – jfc
    Mar 27 at 10:23


















0















I have a Rails 4.2 app. I want to create a script in the lib folder that I will use to create records in my database. So hypothetically:



lib/user_builder.rb



require 'rubygems'
require 'active_record'
require './app/models/application_record.rb'
require './app/models/client.rb'

module UserTheory
class UserBuilder
def initialize
user = User.find_or_initialize_by(id: 1)
user.name = 'Bob'
user.save
end
end
end


I required those files because I was getting NameErrors about those classes. Now I am getting another error:



/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/connection_pool.rb:570:in `retrieve_connection': No connection pool for User (ActiveRecord::ConnectionNotEstablished)



so clearly I am going about this the wrong way.










share|improve this question
























  • instead of putting it in lib, try a directory inside app/ such as app/services. Then you shouldn't need the requires and autoloading should work properly.

    – Scott Bartell
    Mar 27 at 5:26






  • 1





    Why aren't you just using the db/seeds.rb file?

    – Jon
    Mar 27 at 7:03











  • Actually, you can use rake tasks to do your case

    – IlyaOsotov
    Mar 27 at 9:00











  • db/seeds.rb is the way to go here.

    – jfc
    Mar 27 at 10:23














0












0








0








I have a Rails 4.2 app. I want to create a script in the lib folder that I will use to create records in my database. So hypothetically:



lib/user_builder.rb



require 'rubygems'
require 'active_record'
require './app/models/application_record.rb'
require './app/models/client.rb'

module UserTheory
class UserBuilder
def initialize
user = User.find_or_initialize_by(id: 1)
user.name = 'Bob'
user.save
end
end
end


I required those files because I was getting NameErrors about those classes. Now I am getting another error:



/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/connection_pool.rb:570:in `retrieve_connection': No connection pool for User (ActiveRecord::ConnectionNotEstablished)



so clearly I am going about this the wrong way.










share|improve this question














I have a Rails 4.2 app. I want to create a script in the lib folder that I will use to create records in my database. So hypothetically:



lib/user_builder.rb



require 'rubygems'
require 'active_record'
require './app/models/application_record.rb'
require './app/models/client.rb'

module UserTheory
class UserBuilder
def initialize
user = User.find_or_initialize_by(id: 1)
user.name = 'Bob'
user.save
end
end
end


I required those files because I was getting NameErrors about those classes. Now I am getting another error:



/usr/local/bundle/gems/activerecord-4.2.10/lib/active_record/connection_adapters/abstract/connection_pool.rb:570:in `retrieve_connection': No connection pool for User (ActiveRecord::ConnectionNotEstablished)



so clearly I am going about this the wrong way.







ruby-on-rails






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 3:38









Timmy Von Heiss Timmy Von Heiss

1,0328 silver badges19 bronze badges




1,0328 silver badges19 bronze badges















  • instead of putting it in lib, try a directory inside app/ such as app/services. Then you shouldn't need the requires and autoloading should work properly.

    – Scott Bartell
    Mar 27 at 5:26






  • 1





    Why aren't you just using the db/seeds.rb file?

    – Jon
    Mar 27 at 7:03











  • Actually, you can use rake tasks to do your case

    – IlyaOsotov
    Mar 27 at 9:00











  • db/seeds.rb is the way to go here.

    – jfc
    Mar 27 at 10:23


















  • instead of putting it in lib, try a directory inside app/ such as app/services. Then you shouldn't need the requires and autoloading should work properly.

    – Scott Bartell
    Mar 27 at 5:26






  • 1





    Why aren't you just using the db/seeds.rb file?

    – Jon
    Mar 27 at 7:03











  • Actually, you can use rake tasks to do your case

    – IlyaOsotov
    Mar 27 at 9:00











  • db/seeds.rb is the way to go here.

    – jfc
    Mar 27 at 10:23

















instead of putting it in lib, try a directory inside app/ such as app/services. Then you shouldn't need the requires and autoloading should work properly.

– Scott Bartell
Mar 27 at 5:26





instead of putting it in lib, try a directory inside app/ such as app/services. Then you shouldn't need the requires and autoloading should work properly.

– Scott Bartell
Mar 27 at 5:26




1




1





Why aren't you just using the db/seeds.rb file?

– Jon
Mar 27 at 7:03





Why aren't you just using the db/seeds.rb file?

– Jon
Mar 27 at 7:03













Actually, you can use rake tasks to do your case

– IlyaOsotov
Mar 27 at 9:00





Actually, you can use rake tasks to do your case

– IlyaOsotov
Mar 27 at 9:00













db/seeds.rb is the way to go here.

– jfc
Mar 27 at 10:23






db/seeds.rb is the way to go here.

– jfc
Mar 27 at 10:23













0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55369427%2fhow-can-i-access-active-record-classes-to-create-records-from-a-module-class-in%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55369427%2fhow-can-i-access-active-record-classes-to-create-records-from-a-module-class-in%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해