Vote count:
0
I have a model concern which adds a method 't' allowing the models fields to be translated va I18n:
module Translatable
extend ActiveSupport::Concern
def t(field_name)
I18n.t("models.#{self.class.table_name}.#{translation_tag}.#{field_name}")
end
This works fine almost everywhere using:
@model.t(:name)
However I have a select field which uses this code to map the entries:
Model.all.order(name: :asc), :id, :name
And I want :name to use the translatable method instead. The below works, but I'm getting a missing argument error (quite clear why):
Model.all.order(name: :asc), :id, :t
However this doesn't work:
Model.all.order(name: :asc), :id, :t(:name)
What is the correct way to pass variables to methods when they are called as symbols?
asked 1 min ago
How to pass parameters to a symbol method call
Aucun commentaire:
Enregistrer un commentaire