2

I'm trying to set my controller to save multiple languages with an object like this:

{ text: { fr: "francais", en: "English" } }
4

1 回答 1

3

在你的控制器前:(models_controller.rb)

def create
  model = Model.new model_save_param
  model.save
end
def model_save_params
  translations_attributes: params[:model][:text].map { |locale, translation| {locale: locale, text: translation} }
end

在您的模型中:(model.rb)

translates :text
accepts_nested_attributes_for :translations

或者,有一个Gem Globalize Accessor可以完成这项工作

于 2014-03-20T20:32:18.470 回答