[英]Simple_form and globalize gem
我正在使用Ruby on Rails(4.1)開發應用程序,並使用Globalize gem(版本4.0.1)存儲數據的各種翻譯。 問題是,當我使用simple_form的“ globalize_fields_for”方法來生成各種語言環境的表單字段時,出現以下錯誤:
undefined method `globalize_fields_for' for #<SimpleForm::FormBuilder:0x00000106824928>
這是我的觀點(哈姆爾):
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”(或我創建的任何其他語言環境),該屬性有效,因為我的模型中未聲明任何屬性。
我為此停留了幾個小時,因此任何幫助/建議都將不勝感激:)
您可以使用gem globalize3_helpers 。 使用幫助程序globalize_fields_for_locales [:en, :ru, :el]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.