Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute isn't translated if id isn't a Fixnum #20

Closed
kuraga opened this issue Oct 24, 2012 · 1 comment
Closed

Attribute isn't translated if id isn't a Fixnum #20

kuraga opened this issue Oct 24, 2012 · 1 comment

Comments

@kuraga
Copy link
Contributor

kuraga commented Oct 24, 2012

According to this code, ActiveEnum''s enumerate attribute isn't translated if id isn't a Fixnum. For example I can use a String for id. Then I get row[0] (untranslated) but not row[1] (translated);

# lib/active_enum/base.rb#57
# ActiveEnum::Base
      def get(index)
        if index.is_a?(Fixnum)
          row = store.get_by_id(index)
          row[1] if row
        else
          row = store.get_by_name(index)
          row[0] if row
        end
      end
# lib/active_enum/storage/i18n_store.rb
# ActiveEnum::Storage::I18n
      def get_by_name(name)
        row = _values.rassoc(name.to_s)
        [ row[0], translate(row[1]), row[2] ].compact if row
      end

Why? Thanks.

@adzap
Copy link
Owner

adzap commented Oct 29, 2012

String ids are not supported. If you pass a string to get it will look for the matching name and return the id, if found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants