0

I am developing an application with Ruby on Rails (4.1) and I use the Globalize gem (version 4.0.1) to store various translations of my data. The problem is that when I use the "globalize_fields_for" method of simple_form in order to generate the form fields for the various locales, I get the following error:

undefined method `globalize_fields_for' for #<SimpleForm::FormBuilder:0x00000106824928>

Here is my view (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'

the "@locales" variable has my locales (['el', 'en', 'ru'].

My model is as follows:

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

If I use the "simple_fields_for" helper, then I get an error that says that I have undefined attribute "el" (or any other of the locales that I have created) which is valid as there is none declared in my model.

I am stuck for a couple of hours on this so any help/suggestion will be appreciated :)

manosagent
  • 614
  • 8
  • 18

1 Answers1

1

You can use gem globalize3_helpers. Use helper globalize_fields_for_locales [:en, :ru, :el]

William Weckl
  • 2,435
  • 4
  • 26
  • 43
  • When one uses the globalize3_helpers, you get this in the terminal: ------------------- Bundler could not find compatible versions for gem "globalize": In Gemfile: globalize3_helpers (>= 0) ruby depends on globalize (~> 3.0.0) ruby globalize (4.0.2) – Pavan Katepalli Aug 17 '14 at 05:33
  • 1
    Did you remove the globalize gem from the Gemfile? The globalize3_helpers gem is a complement of the globalize gem, so you have to maintain the two gems at the Gemfile. Hope it helps. – William Weckl Sep 03 '14 at 13:37
  • 2
    I got everything to work. Here's my gemfile: gem "friendly_id", "~> 5.0.1", gem 'i18n', '~> 0.6.11' (had to include this to get friendly_id generator to work - also works in conjunction with the globalize gem and globalize-accessors gem), gem 'globalize', '~> 4.0.2' (let's you use multiple locales for one model without making a ton of columns), gem 'globalize-accessors', '~> 0.1.5' (Easily access (read and write) globalize translated fields without fiddling with locale gem), 'batch_translations' (needed this to get globalize_fields_for to work) – Pavan Katepalli Sep 03 '14 at 18:06