How to use rails-i18n in association with ActiveRecordError?

I am trying to translate https://github.com/lifo/docrails/blob/master/activerecord/lib/active_record/associations.rb

In my controller file, I have:

@book = Book.find(params[:id]) begin @book.destroy rescue ActiveRecord::DeleteRestrictionError => e flash[:error]= e.message # <<< Translate this message ? end 

This is the translation file I'm using: https://github.com/svenfuchs/rails-i18n/blob/master/rails/locale/th.rb

How to write code for translate "#{e.message}" ?

+4
source share
1 answer

You can use this in your en.yml file

 activerecord: book: error: 'book error: %{e}' 

and u can block cheer salvage block with this

 flash[:error] = t("book.error") % {:e => e.message} 

it works in ma case

+1
source

Source: https://habr.com/ru/post/1383875/


All Articles