globalize / globalize-accessors

Easily access (read and write) globalize translated fields without fiddling with locale
Other
110 stars 43 forks source link

Rails 6 "working" #39

Open henriquekraemer opened 5 years ago

henriquekraemer commented 5 years ago

Looks like this gem wont be supported anymore. So, if anybody tries to use this on rails 6, here it goes:

My gem set:

model -> globalize_accessors

The :locales and :attributes options are optional. Their default values are:

:locales => I18n.available_locales :attributes => translated_attribute_names

Apparently, the defaults ain't working, you should define yourself!

globalize_accessors :locales => I18n.available_locales, :attributes => translated_attribute_names
class FaqCategory < ApplicationRecord
    translates :description, touch: true
    globalize_accessors :locales => I18n.available_locales, :attributes => translated_attribute_names
end

controller -> globalize_accessors Strong parameters aren't working either.

Example with strong parameters:

params.require(:product).permit(*Product.globalize_attribute_names) If you need to permit non-translatable attributes as well, you could include them with:

permitted = Product.globalize_attribute_names + [:position] params.require(:product).permit(*permitted)

You can "workaround" with:

params.permit(*FaqCategory.globalize_attribute_names)

In my case, I'm building a simple FAQ API for our application, so this won't be an issue.

maelevadili commented 4 years ago

Henrique's solution works fine 👍 In my case I also used the batch_translations gem to handle all my model attributes translations in one single form.