0

我正在使用 Ruby on Rails (4.1) 开发一个应用程序,并使用 Globalize gem(4.0.1 版)来存储我的数据的各种翻译。问题是,当我使用 simple_form 的“globalize_fields_for”方法为各种语言环境生成表单字段时,我收到以下错误:

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'

“@locales”变量有我的语言环境(['el','en','ru']。

我的模型如下:

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

如果我使用“simple_fields_for”帮助程序,那么我会收到一个错误,指出我有未定义的属性“el”(或我创建的任何其他语言环境),这是有效的,因为在我的模型中没有声明。

我被困了几个小时,所以任何帮助/建议将不胜感激:)

4

1 回答 1

1

您可以使用 gem globalize3_helpers。使用助手globalize_fields_for_locales [:en, :ru, :el]

于 2014-07-14T19:17:53.330 回答