我正在使用Ruby on Rails(4.1)开发一个应用程序,我使用Globalize gem(版本4.0.1)来存储我的数据的各种翻译。问题是当我使用" globalize_fields_for" simple_form的方法为了生成各种语言环境的表单字段,我得到以下错误:
undefined method `globalize_fields_for' for #<SimpleForm::FormBuilder:0x00000106824928>
这是我的观点(haml):
h3.title New Static Page
%hr
= simple_form_for [:admin, @static_page] do |f|
%dl.tabs{ "data-tab" => "" }
- @locales.each_with_index do |lang, index|
- klass = index == 0 ? 'active' : ''
%dd{ class: klass }= link_to t("admin.languages.#{lang}"), "#panel2-#{index + 1}", class: "#{lang} flag"
.tabs-content
- @locales.each_with_index do |lang, index|
- klass2 = index == 0 ? 'active' : ''
.content{ class: klass2, id: "panel2-#{index + 1}"}
= f.globalize_fields_for lang.to_sym do |g|
= g.input :title, label: "Title"
= g.cktext_area :body, rows: 15, class: 'ckeditor'
= f.button :submit, t('admin.buttons.submit'), class: 'new-submission'
&#34; @ locales&#34;变量有我的语言环境([&#39; el&#39;,&#39; en&#39;,&#39; ru&#39;]。
我的模型如下:
class StaticPage < ActiveRecord::Base
extend FriendlyId
friendly_id :title, use: [:slugged, :history]
# Validations
validates :title, presence: true, length: { maximum: 100 }
validates_presence_of :body
# Associations
translates :title, :body
has_many :translations
accepts_nested_attributes_for :translations
end
如果我使用&#34; simple_fields_for&#34;帮手,然后我得到一个错误,说我有未定义的属性&#34; el&#34; (或我创建的任何其他语言环境),这是有效的,因为我的模型中没有声明。
我被困了几个小时,所以任何帮助/建议将不胜感激:)