ruby on rails - How to pass parameters to a symbol method call -


I have a model concern which adds a method 'T' to translate models fields. I18n:

 Expand translatable for the  module. Activate support: concern DEF T (field_name) I18n.t ("Model. # {Self.class.table_name}. # {Translation_tag}. {{Field_name}") End  

Ideal:

  class models & lt; Translatable in ActiveRecord :: Base:  

It uses almost everywhere:

  @model. (Name)  

However, I have a selection field that uses this code to map entries:

  Model.all .order (name :: asc) ,: id ,: name  

and I want: instead of using the translatable method, the name works below, but I'm missing Logic error is getting (clear):

  Model.all.order (name: asc) ,: id,: t  

though This does not work:

  model.all.order (name :: asc) ,: id,: (t (: name)  

What is the correct way to pass the variable to the methods when they are called symbols?

Either make a dedicated method to handle the name model or use map before selecting your code.

>
  def i18n_name t (: name) end model.all.order (name :: asc) ,: id ,: i18n_name  

or

  model.all.map {| P | [Pt (: name), p.id]}  

More info

Note: I will not recommend keeping i18n translation in my model, it should be present in presentations needed . Take a look at


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -