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

Exception raised when boolean ingredient is used for element preview text #2329

Closed
robinboening opened this issue May 4, 2022 · 6 comments · Fixed by #2367
Closed

Exception raised when boolean ingredient is used for element preview text #2329

robinboening opened this issue May 4, 2022 · 6 comments · Fixed by #2367

Comments

@robinboening
Copy link
Contributor

robinboening commented May 4, 2022

Steps to reproduce

  1. Create element with boolean ingredient (used for "preview text")
  2. Throw this element on a Page

Expected behavior

In the elements list, the element's header part should render "true".

Actual behavior

Error is raised: Exception: undefined method `empty?' for true:TrueClass

The error is raised inside the sanitize helper as true is passed and boolean type can not be handled.
See https://github.com/AlchemyCMS/alchemy_cms/blob/main/app/views/alchemy/admin/elements/_header.html.erb#L18

A quick fix is to always cast the value to string when passing it to sanitize.

System configuration

  • Alchemy Version: 6.0.3
  • Rails Version: 6.1
@tvdeyen
Copy link
Member

tvdeyen commented May 5, 2022

Hey. Could it be that the translation of the essence boolean is not a String, but cast to a Boolean instead?

def preview_text(_max_length = nil)
Alchemy.t(value, scope: "ingredient_values.boolean")
end

@robinboening
Copy link
Contributor Author

robinboening commented May 5, 2022

Hey. Could it be that the translation of the essence boolean is not a String, but cast to a Boolean instead?

Good point, that's the issue indeed. The en.yml provided by alchemy_cms contains ingredient_values.boolean, while the locale files in alchemy_i18n do not.

It means it currently works in english, but not in any other language.

@tvdeyen
Copy link
Member

tvdeyen commented Jun 10, 2022

Ok. This is an issue of alchemy_i18n then?

@github-actions
Copy link

This issue has not seen any activity in a long time.
Please create a pull request with a fix or ask someone of the community if they can help.
This issue will be closed in 7 days if no further activity happens.

@github-actions github-actions bot added the Stale label Aug 10, 2022
@tvdeyen
Copy link
Member

tvdeyen commented Aug 14, 2022

Maybe we cast the preview_text value to string before passing to I18n?

tvdeyen added a commit to tvdeyen/alchemy_cms that referenced this issue Sep 2, 2022
If the translation is missing I18n returns a boolean instead
of a string. Cast to string unless the value is nil.

Closes AlchemyCMS#2329
@tvdeyen
Copy link
Member

tvdeyen commented Sep 2, 2022

@robinboening fixed by #2367

tvdeyen added a commit that referenced this issue Sep 4, 2022
If the translation is missing I18n returns a boolean instead
of a string. Cast to string unless the value is nil.

Closes #2329
dbwinger pushed a commit to dbwinger/alchemy_cms that referenced this issue Mar 20, 2023
If the translation is missing I18n returns a boolean instead
of a string. Cast to string unless the value is nil.

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

Successfully merging a pull request may close this issue.

2 participants