gpt4 book ai didi

ruby-on-rails - Globalize3——将翻译保存到数据库

转载 作者:行者123 更新时间:2023-12-04 07:37:23 25 4
gpt4 key购买 nike

大家好,我是新手,希望获得有关将语言环境翻译保存到数据库的帮助。

我有这个表格

= form_for @restaurant do |f|
= f.fields_for :en_info do |restaurant_en|
%h4 English Information
= restaurant_en.label :title
= restaurant_en.text_field :title
= restaurant_en.label :description
= restaurant_en.text_area :description
= f.fields_for :ar_info do |restaurant_ar|
%h4 Arabic Information
= restaurant_ar.label :title
= restaurant_ar.text_field :title
= restaurant_ar.label :description
= restaurant_ar.text_area :description
= f.submit

在添加阿拉伯语表单字段之前,我可以使用 Controller 中的创建方法将模型保存到数据库

 def create
@restaurant = Restaurant.create params[:restaurant][:en_info]
end

但是如何将阿拉伯语翻译从表单保存到数据库?

最佳答案

尝试使用 globalize3_helpers gem。

= form_for @restaurant do |f|

- f.globalize_fields_for_locale :en do |l|
= l.input :title
= l.input :description, as: :text

- f.globalize_fields_for_locale :ar do |l|
= l.input :title
= l.input :description, as: :text

关于ruby-on-rails - Globalize3——将翻译保存到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13728748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com