ruby - Rails - Export DB to CSV not reading from translation file -


I have seen many useful suggestions here but my problem has not been corrected so far. I am making a redin plugin (Ruby on Rail) and I have a button which exports DB to a CSV file. This part works just fine

My problem is that the column names in the CSV file are not being translated, it seems that the call has not been changed from human_attribute_name . Does anyone tell me where I've gone wrong and can help me fix it?

I have followed this tutorial primarily:

AP / model / person.rbi

  def self.to_csv (option = { }) CSV.generate (options) do | Csv | CSV & LT; & Lt; User.attribute_names.map {| C | User.human_attribute_name (c)} # I can use instead: # csv & lt; & Lt; User.human_attribute_names User.all.each | User | CSV & LT; & Lt; User.attributes.values ​​end end end  

config / locales / en.yml

  en: activerecord: attributes: user: col1: "column 1 "Col2:" column 2 " 

found this solution that works:

AP / Modal / UserRb

  DEFSE self.to_csv (OPTION = {} CSV generates (options) do | Csv | @ Cols = user.attribute_names # [1 ..- 1] To remove the output from the first column from the first column & lt; & Lt; @ Cols.map {| C | I18t.t c, scope: [: active record ,: features, user]} user. User | CSV & LT; & Lt; User.attributes.value_at (* @ cols) End End  

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? -