uninitialized constant *ModelXYZ* in seeds.rb. Wrong config?
I have some simple Rails 5 API models, e.g. class Training
. Executing
Training.delete_all
works like expected from Rails console.
The exact same line of code results in
in `<main>': uninitialized constant Training (NameError)
when used (as first line) in seeds.rb.
I cannot guess why.
ruby-on-rails seed
add a comment |
I have some simple Rails 5 API models, e.g. class Training
. Executing
Training.delete_all
works like expected from Rails console.
The exact same line of code results in
in `<main>': uninitialized constant Training (NameError)
when used (as first line) in seeds.rb.
I cannot guess why.
ruby-on-rails seed
What command do you use to run your seeds?
– Marcin Kołodziej
Dec 30 '18 at 16:02
well, inside RubyMine it is bash -c"RBENV_VERSION=2.5.3 /usr/local/bin/rbenv exec bundle exec ruby PATH_TO_PROJECT/db/seeds.rb".
On command line just railsdb:seed
– Alexander Stippler
Dec 30 '18 at 16:44
1
Usebundle exec rails db:seed
then to properly load the environment :)
– Marcin Kołodziej
Dec 30 '18 at 16:45
1
very strange. Your suggestion helps on command line. It does not inside RubyMine. But if I run db:setup in RubyMine, it works, too. But not standalone only running db:seed. Seems to be a RubyMine specific problem additionally :(. And bundle exec is also called inside RubyMine. Thanks!
– Alexander Stippler
Dec 30 '18 at 16:53
add a comment |
I have some simple Rails 5 API models, e.g. class Training
. Executing
Training.delete_all
works like expected from Rails console.
The exact same line of code results in
in `<main>': uninitialized constant Training (NameError)
when used (as first line) in seeds.rb.
I cannot guess why.
ruby-on-rails seed
I have some simple Rails 5 API models, e.g. class Training
. Executing
Training.delete_all
works like expected from Rails console.
The exact same line of code results in
in `<main>': uninitialized constant Training (NameError)
when used (as first line) in seeds.rb.
I cannot guess why.
ruby-on-rails seed
ruby-on-rails seed
asked Dec 30 '18 at 14:52
Alexander StipplerAlexander Stippler
345
345
What command do you use to run your seeds?
– Marcin Kołodziej
Dec 30 '18 at 16:02
well, inside RubyMine it is bash -c"RBENV_VERSION=2.5.3 /usr/local/bin/rbenv exec bundle exec ruby PATH_TO_PROJECT/db/seeds.rb".
On command line just railsdb:seed
– Alexander Stippler
Dec 30 '18 at 16:44
1
Usebundle exec rails db:seed
then to properly load the environment :)
– Marcin Kołodziej
Dec 30 '18 at 16:45
1
very strange. Your suggestion helps on command line. It does not inside RubyMine. But if I run db:setup in RubyMine, it works, too. But not standalone only running db:seed. Seems to be a RubyMine specific problem additionally :(. And bundle exec is also called inside RubyMine. Thanks!
– Alexander Stippler
Dec 30 '18 at 16:53
add a comment |
What command do you use to run your seeds?
– Marcin Kołodziej
Dec 30 '18 at 16:02
well, inside RubyMine it is bash -c"RBENV_VERSION=2.5.3 /usr/local/bin/rbenv exec bundle exec ruby PATH_TO_PROJECT/db/seeds.rb".
On command line just railsdb:seed
– Alexander Stippler
Dec 30 '18 at 16:44
1
Usebundle exec rails db:seed
then to properly load the environment :)
– Marcin Kołodziej
Dec 30 '18 at 16:45
1
very strange. Your suggestion helps on command line. It does not inside RubyMine. But if I run db:setup in RubyMine, it works, too. But not standalone only running db:seed. Seems to be a RubyMine specific problem additionally :(. And bundle exec is also called inside RubyMine. Thanks!
– Alexander Stippler
Dec 30 '18 at 16:53
What command do you use to run your seeds?
– Marcin Kołodziej
Dec 30 '18 at 16:02
What command do you use to run your seeds?
– Marcin Kołodziej
Dec 30 '18 at 16:02
well, inside RubyMine it is bash -c
"RBENV_VERSION=2.5.3 /usr/local/bin/rbenv exec bundle exec ruby PATH_TO_PROJECT/db/seeds.rb".
On command line just rails db:seed
– Alexander Stippler
Dec 30 '18 at 16:44
well, inside RubyMine it is bash -c
"RBENV_VERSION=2.5.3 /usr/local/bin/rbenv exec bundle exec ruby PATH_TO_PROJECT/db/seeds.rb".
On command line just rails db:seed
– Alexander Stippler
Dec 30 '18 at 16:44
1
1
Use
bundle exec rails db:seed
then to properly load the environment :)– Marcin Kołodziej
Dec 30 '18 at 16:45
Use
bundle exec rails db:seed
then to properly load the environment :)– Marcin Kołodziej
Dec 30 '18 at 16:45
1
1
very strange. Your suggestion helps on command line. It does not inside RubyMine. But if I run db:setup in RubyMine, it works, too. But not standalone only running db:seed. Seems to be a RubyMine specific problem additionally :(. And bundle exec is also called inside RubyMine. Thanks!
– Alexander Stippler
Dec 30 '18 at 16:53
very strange. Your suggestion helps on command line. It does not inside RubyMine. But if I run db:setup in RubyMine, it works, too. But not standalone only running db:seed. Seems to be a RubyMine specific problem additionally :(. And bundle exec is also called inside RubyMine. Thanks!
– Alexander Stippler
Dec 30 '18 at 16:53
add a comment |
1 Answer
1
active
oldest
votes
As established in the comments, using bundle exec ruby db/seeds.rb
won't work as it won't prepare the environment (load all the models, etc.).
Proper way of running Rails seeds is by bundle exec rails db:seed
.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53978616%2funinitialized-constant-modelxyz-in-seeds-rb-wrong-config%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As established in the comments, using bundle exec ruby db/seeds.rb
won't work as it won't prepare the environment (load all the models, etc.).
Proper way of running Rails seeds is by bundle exec rails db:seed
.
add a comment |
As established in the comments, using bundle exec ruby db/seeds.rb
won't work as it won't prepare the environment (load all the models, etc.).
Proper way of running Rails seeds is by bundle exec rails db:seed
.
add a comment |
As established in the comments, using bundle exec ruby db/seeds.rb
won't work as it won't prepare the environment (load all the models, etc.).
Proper way of running Rails seeds is by bundle exec rails db:seed
.
As established in the comments, using bundle exec ruby db/seeds.rb
won't work as it won't prepare the environment (load all the models, etc.).
Proper way of running Rails seeds is by bundle exec rails db:seed
.
answered Dec 30 '18 at 16:49
Marcin KołodziejMarcin Kołodziej
4,3111315
4,3111315
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53978616%2funinitialized-constant-modelxyz-in-seeds-rb-wrong-config%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
What command do you use to run your seeds?
– Marcin Kołodziej
Dec 30 '18 at 16:02
well, inside RubyMine it is bash -c
"RBENV_VERSION=2.5.3 /usr/local/bin/rbenv exec bundle exec ruby PATH_TO_PROJECT/db/seeds.rb".
On command line just railsdb:seed
– Alexander Stippler
Dec 30 '18 at 16:44
1
Use
bundle exec rails db:seed
then to properly load the environment :)– Marcin Kołodziej
Dec 30 '18 at 16:45
1
very strange. Your suggestion helps on command line. It does not inside RubyMine. But if I run db:setup in RubyMine, it works, too. But not standalone only running db:seed. Seems to be a RubyMine specific problem additionally :(. And bundle exec is also called inside RubyMine. Thanks!
– Alexander Stippler
Dec 30 '18 at 16:53