undefined method `coffeeprocess' for nil:NilClass
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm getting the above error when trying to reference an associated value from a different table.
I have two models with a one-to-many association.
class Roast < ApplicationRecord
has_one :processing
class Processing < ApplicationRecord
belongs_to :roast
I have added a process_id
column to the Roasts
table.
Roasts
represent an individual coffee roast, and processing
represents one of three processes in the production of that coffee.
Processing
is populated with three static strings, that I make available in the roasts form via a 'collection_select' field.
<%= form.collection_select(:process_id, Processing.order(:coffeeprocess), :id, :coffeeprocess, :prompt => 'Select Process') %>
I am able to assign a process to an individual roast, and I can see the corresponding ID in the process_id
column.
However, when I go to the roasts
show page, I get the error: undefined method 'coffeeprocess' for nil:NilClass
which I understand is telling me the value is Nil.
I'm using the following in my show page.
<%= @roast.processing.coffeeprocess %>
Any ideas where this is going wrong?
ruby-on-rails activerecord
add a comment |
I'm getting the above error when trying to reference an associated value from a different table.
I have two models with a one-to-many association.
class Roast < ApplicationRecord
has_one :processing
class Processing < ApplicationRecord
belongs_to :roast
I have added a process_id
column to the Roasts
table.
Roasts
represent an individual coffee roast, and processing
represents one of three processes in the production of that coffee.
Processing
is populated with three static strings, that I make available in the roasts form via a 'collection_select' field.
<%= form.collection_select(:process_id, Processing.order(:coffeeprocess), :id, :coffeeprocess, :prompt => 'Select Process') %>
I am able to assign a process to an individual roast, and I can see the corresponding ID in the process_id
column.
However, when I go to the roasts
show page, I get the error: undefined method 'coffeeprocess' for nil:NilClass
which I understand is telling me the value is Nil.
I'm using the following in my show page.
<%= @roast.processing.coffeeprocess %>
Any ideas where this is going wrong?
ruby-on-rails activerecord
Fire uprails c
and see if theroast
in question really does have aprocessing
object set.
– vich
Nov 26 '18 at 21:47
add a comment |
I'm getting the above error when trying to reference an associated value from a different table.
I have two models with a one-to-many association.
class Roast < ApplicationRecord
has_one :processing
class Processing < ApplicationRecord
belongs_to :roast
I have added a process_id
column to the Roasts
table.
Roasts
represent an individual coffee roast, and processing
represents one of three processes in the production of that coffee.
Processing
is populated with three static strings, that I make available in the roasts form via a 'collection_select' field.
<%= form.collection_select(:process_id, Processing.order(:coffeeprocess), :id, :coffeeprocess, :prompt => 'Select Process') %>
I am able to assign a process to an individual roast, and I can see the corresponding ID in the process_id
column.
However, when I go to the roasts
show page, I get the error: undefined method 'coffeeprocess' for nil:NilClass
which I understand is telling me the value is Nil.
I'm using the following in my show page.
<%= @roast.processing.coffeeprocess %>
Any ideas where this is going wrong?
ruby-on-rails activerecord
I'm getting the above error when trying to reference an associated value from a different table.
I have two models with a one-to-many association.
class Roast < ApplicationRecord
has_one :processing
class Processing < ApplicationRecord
belongs_to :roast
I have added a process_id
column to the Roasts
table.
Roasts
represent an individual coffee roast, and processing
represents one of three processes in the production of that coffee.
Processing
is populated with three static strings, that I make available in the roasts form via a 'collection_select' field.
<%= form.collection_select(:process_id, Processing.order(:coffeeprocess), :id, :coffeeprocess, :prompt => 'Select Process') %>
I am able to assign a process to an individual roast, and I can see the corresponding ID in the process_id
column.
However, when I go to the roasts
show page, I get the error: undefined method 'coffeeprocess' for nil:NilClass
which I understand is telling me the value is Nil.
I'm using the following in my show page.
<%= @roast.processing.coffeeprocess %>
Any ideas where this is going wrong?
ruby-on-rails activerecord
ruby-on-rails activerecord
edited Nov 26 '18 at 20:47
Simon Cooper
asked Nov 26 '18 at 17:36
Simon CooperSimon Cooper
589827
589827
Fire uprails c
and see if theroast
in question really does have aprocessing
object set.
– vich
Nov 26 '18 at 21:47
add a comment |
Fire uprails c
and see if theroast
in question really does have aprocessing
object set.
– vich
Nov 26 '18 at 21:47
Fire up
rails c
and see if the roast
in question really does have a processing
object set.– vich
Nov 26 '18 at 21:47
Fire up
rails c
and see if the roast
in question really does have a processing
object set.– vich
Nov 26 '18 at 21:47
add a comment |
1 Answer
1
active
oldest
votes
You are getting nil:NilClass
because Rails doesn't understand the relationship between Roasts and Processing.
Try
class Roast < ApplicationRecord
belongs_to :processing
See the documentation for ActiveRecord Associations for more.
I believe it would be the other way round and have updated my OP. However, I still get the same result either way.
– Simon Cooper
Nov 26 '18 at 20:47
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%2f53486325%2fundefined-method-coffeeprocess-for-nilnilclass%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
You are getting nil:NilClass
because Rails doesn't understand the relationship between Roasts and Processing.
Try
class Roast < ApplicationRecord
belongs_to :processing
See the documentation for ActiveRecord Associations for more.
I believe it would be the other way round and have updated my OP. However, I still get the same result either way.
– Simon Cooper
Nov 26 '18 at 20:47
add a comment |
You are getting nil:NilClass
because Rails doesn't understand the relationship between Roasts and Processing.
Try
class Roast < ApplicationRecord
belongs_to :processing
See the documentation for ActiveRecord Associations for more.
I believe it would be the other way round and have updated my OP. However, I still get the same result either way.
– Simon Cooper
Nov 26 '18 at 20:47
add a comment |
You are getting nil:NilClass
because Rails doesn't understand the relationship between Roasts and Processing.
Try
class Roast < ApplicationRecord
belongs_to :processing
See the documentation for ActiveRecord Associations for more.
You are getting nil:NilClass
because Rails doesn't understand the relationship between Roasts and Processing.
Try
class Roast < ApplicationRecord
belongs_to :processing
See the documentation for ActiveRecord Associations for more.
answered Nov 26 '18 at 18:05
Tristin BakerTristin Baker
83
83
I believe it would be the other way round and have updated my OP. However, I still get the same result either way.
– Simon Cooper
Nov 26 '18 at 20:47
add a comment |
I believe it would be the other way round and have updated my OP. However, I still get the same result either way.
– Simon Cooper
Nov 26 '18 at 20:47
I believe it would be the other way round and have updated my OP. However, I still get the same result either way.
– Simon Cooper
Nov 26 '18 at 20:47
I believe it would be the other way round and have updated my OP. However, I still get the same result either way.
– Simon Cooper
Nov 26 '18 at 20:47
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%2f53486325%2fundefined-method-coffeeprocess-for-nilnilclass%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
Fire up
rails c
and see if theroast
in question really does have aprocessing
object set.– vich
Nov 26 '18 at 21:47