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

Get original JSONB attribute hash #7

Open
ChristianClassen opened this issue May 28, 2017 · 2 comments
Open

Get original JSONB attribute hash #7

ChristianClassen opened this issue May 28, 2017 · 2 comments

Comments

@ChristianClassen
Copy link

Hello,

first of all, thanks for this great gem!

I would like to know, if there is a way to simply get back the whole data hash and not just a localized version of the nested content when reading a JSONB attribute?

Example:

# I18n.locale = :en
# Currently
Post.first.description #=> "Hello World"

# I need the whole JSONB hash
Post.first.description #=> {'en': 'Hello World', 'de': 'Hallo Welt'}
@olegantonyan
Copy link
Owner

Hi! Thanks for good feedback

One way to do this is to use hash-like access:

Post.first[:description] #=> {'en' => 'Hello World', 'de' => 'Hallo Welt'}

This may not be the best solution though, so suggestions are welcome

@chumakoff
Copy link

chumakoff commented Dec 26, 2018

You should also add the ability to pass the needed locale as a parameter. For example:

@post.description(locale: "en")

or as part of the method name:

@post.description_en

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

3 participants