Convert JSON to Rails 3

I am currently doing this in the controller:

def index @orders = Order.all respond_to do |format| { format.html format.js { render json: @orders.as_json() } end 

I have an order status field. The values ​​for this field are in English and must be translated into Dutch. The problem is that calling as_json does not automatically translate data into Dutch. YML file, current and standard locale all work correctly. (calling I18n.t works, but how does it work with as_json ()?)

Thanks!

+6
source share
1 answer

You can override as_json in your model and call i18n from this method.

+1
source

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


All Articles