Plural of an enum called access
I have an enum called access defined on an account model.
enum access: [:basic, :silver, :gold, :platinum]
which works fine, e.g. account.gold!
sets the value to 'gold' and then account.access
returns 'gold'. Accordingly, I should be able to list the hash of access values with the plural of acesss
, but account.accesses
, returns
NoMethodError: undefined method `accesses' for #<Account:0x00007f9e7827e408>
Did you mean? access
access?
access=
If I do 'access'.pluralize
it returns accesses
, so why isnt account.accesses
working?
ruby-on-rails
add a comment |
I have an enum called access defined on an account model.
enum access: [:basic, :silver, :gold, :platinum]
which works fine, e.g. account.gold!
sets the value to 'gold' and then account.access
returns 'gold'. Accordingly, I should be able to list the hash of access values with the plural of acesss
, but account.accesses
, returns
NoMethodError: undefined method `accesses' for #<Account:0x00007f9e7827e408>
Did you mean? access
access?
access=
If I do 'access'.pluralize
it returns accesses
, so why isnt account.accesses
working?
ruby-on-rails
Are you sure that RoR pluralizes enums? I know it will do that with database entities, but I don't see the point of doing that with an enum.
– Robert Harvey♦
Nov 25 '18 at 22:25
Yes it does, see stackoverflow.com/a/25570511/1299362, and it can be useful because you can write methods that will continue to work after someone adds a different value to the enum.
– Obromios
Nov 25 '18 at 22:32
add a comment |
I have an enum called access defined on an account model.
enum access: [:basic, :silver, :gold, :platinum]
which works fine, e.g. account.gold!
sets the value to 'gold' and then account.access
returns 'gold'. Accordingly, I should be able to list the hash of access values with the plural of acesss
, but account.accesses
, returns
NoMethodError: undefined method `accesses' for #<Account:0x00007f9e7827e408>
Did you mean? access
access?
access=
If I do 'access'.pluralize
it returns accesses
, so why isnt account.accesses
working?
ruby-on-rails
I have an enum called access defined on an account model.
enum access: [:basic, :silver, :gold, :platinum]
which works fine, e.g. account.gold!
sets the value to 'gold' and then account.access
returns 'gold'. Accordingly, I should be able to list the hash of access values with the plural of acesss
, but account.accesses
, returns
NoMethodError: undefined method `accesses' for #<Account:0x00007f9e7827e408>
Did you mean? access
access?
access=
If I do 'access'.pluralize
it returns accesses
, so why isnt account.accesses
working?
ruby-on-rails
ruby-on-rails
asked Nov 25 '18 at 22:24
ObromiosObromios
4,43923267
4,43923267
Are you sure that RoR pluralizes enums? I know it will do that with database entities, but I don't see the point of doing that with an enum.
– Robert Harvey♦
Nov 25 '18 at 22:25
Yes it does, see stackoverflow.com/a/25570511/1299362, and it can be useful because you can write methods that will continue to work after someone adds a different value to the enum.
– Obromios
Nov 25 '18 at 22:32
add a comment |
Are you sure that RoR pluralizes enums? I know it will do that with database entities, but I don't see the point of doing that with an enum.
– Robert Harvey♦
Nov 25 '18 at 22:25
Yes it does, see stackoverflow.com/a/25570511/1299362, and it can be useful because you can write methods that will continue to work after someone adds a different value to the enum.
– Obromios
Nov 25 '18 at 22:32
Are you sure that RoR pluralizes enums? I know it will do that with database entities, but I don't see the point of doing that with an enum.
– Robert Harvey♦
Nov 25 '18 at 22:25
Are you sure that RoR pluralizes enums? I know it will do that with database entities, but I don't see the point of doing that with an enum.
– Robert Harvey♦
Nov 25 '18 at 22:25
Yes it does, see stackoverflow.com/a/25570511/1299362, and it can be useful because you can write methods that will continue to work after someone adds a different value to the enum.
– Obromios
Nov 25 '18 at 22:32
Yes it does, see stackoverflow.com/a/25570511/1299362, and it can be useful because you can write methods that will continue to work after someone adds a different value to the enum.
– Obromios
Nov 25 '18 at 22:32
add a comment |
2 Answers
2
active
oldest
votes
The plural method needs to be called on the model class (not on the instance of the class):
2.5.3 :001 > Account.accesses
=> {"basic"=>0, "silver"=>1, "gold"=>2, "platinum"=>3}
See the example here. See the actual code here. It defines the method on the class.
add a comment |
I think it should work if you try the plural form:
Account.accesses
The mappings are exposed through a class method with the pluralized attribute name.
Check the guide here: https://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html
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%2f53472618%2fplural-of-an-enum-called-access%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The plural method needs to be called on the model class (not on the instance of the class):
2.5.3 :001 > Account.accesses
=> {"basic"=>0, "silver"=>1, "gold"=>2, "platinum"=>3}
See the example here. See the actual code here. It defines the method on the class.
add a comment |
The plural method needs to be called on the model class (not on the instance of the class):
2.5.3 :001 > Account.accesses
=> {"basic"=>0, "silver"=>1, "gold"=>2, "platinum"=>3}
See the example here. See the actual code here. It defines the method on the class.
add a comment |
The plural method needs to be called on the model class (not on the instance of the class):
2.5.3 :001 > Account.accesses
=> {"basic"=>0, "silver"=>1, "gold"=>2, "platinum"=>3}
See the example here. See the actual code here. It defines the method on the class.
The plural method needs to be called on the model class (not on the instance of the class):
2.5.3 :001 > Account.accesses
=> {"basic"=>0, "silver"=>1, "gold"=>2, "platinum"=>3}
See the example here. See the actual code here. It defines the method on the class.
answered Nov 25 '18 at 22:31
Lenin Raj RajasekaranLenin Raj Rajasekaran
16k1171114
16k1171114
add a comment |
add a comment |
I think it should work if you try the plural form:
Account.accesses
The mappings are exposed through a class method with the pluralized attribute name.
Check the guide here: https://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html
add a comment |
I think it should work if you try the plural form:
Account.accesses
The mappings are exposed through a class method with the pluralized attribute name.
Check the guide here: https://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html
add a comment |
I think it should work if you try the plural form:
Account.accesses
The mappings are exposed through a class method with the pluralized attribute name.
Check the guide here: https://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html
I think it should work if you try the plural form:
Account.accesses
The mappings are exposed through a class method with the pluralized attribute name.
Check the guide here: https://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html
answered Nov 25 '18 at 22:30
John BakerJohn Baker
1,043411
1,043411
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%2f53472618%2fplural-of-an-enum-called-access%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
Are you sure that RoR pluralizes enums? I know it will do that with database entities, but I don't see the point of doing that with an enum.
– Robert Harvey♦
Nov 25 '18 at 22:25
Yes it does, see stackoverflow.com/a/25570511/1299362, and it can be useful because you can write methods that will continue to work after someone adds a different value to the enum.
– Obromios
Nov 25 '18 at 22:32