Plural of an enum called access












1















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?










share|improve this question























  • 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
















1















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?










share|improve this question























  • 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














1












1








1








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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



















  • 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












2 Answers
2






active

oldest

votes


















1














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.






share|improve this answer































    1














    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






    share|improve this answer























      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%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









      1














      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.






      share|improve this answer




























        1














        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.






        share|improve this answer


























          1












          1








          1







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 25 '18 at 22:31









          Lenin Raj RajasekaranLenin Raj Rajasekaran

          16k1171114




          16k1171114

























              1














              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






              share|improve this answer




























                1














                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






                share|improve this answer


























                  1












                  1








                  1







                  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






                  share|improve this answer













                  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







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 25 '18 at 22:30









                  John BakerJohn Baker

                  1,043411




                  1,043411






























                      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%2f53472618%2fplural-of-an-enum-called-access%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

                      404 Error Contact Form 7 ajax form submitting

                      How to know if a Active Directory user can login interactively

                      Refactoring coordinates for Minecraft Pi buildings written in Python