Frage

I am using rails4, activeadmin, globalize and activeadmin-globalize. I created a test application but it's not working properly for me.

I have a model class model.rb

class Post < ActiveRecord::Base
  active_admin_translates :title, :text do
    validates_presence_of :title
  end
end

And appropriate migration

class CreatePosts < ActiveRecord::Migration
  def up
    create_table :posts do |t|
      t.timestamps
    end
    Post.create_translation_table! title: :string, text: :text
  end

  def down
    drop_table :posts
    Post.drop_translation_table!
  end
end

Active admin page is configured like this

ActiveAdmin.register Post do
  permit_params :title, :text, translations_attributes: [:title, :text, :locale]

  index do
    translation_status
    default_actions
  end

  form do |f|
    f.translated_inputs 'Translated fields', switch_locale: false do |t|
      t.input :title
      t.input :text
    end
    f.actions
  end
end

When I create new record in ActiveAdmin then everything works well and localisations are saved. The problem is that when I try to edit and save that record, nothing is changed.

Can anybody tell me what am I doing wrong? Is there any working example solution that I can download and try myself?

Update:

I just discovered that whenever I try to update record, new tuple of translation records are created in translation table. ActiveAdmin still sees the first one.

War es hilfreich?

Lösung

You have to add :id to translations_attributes at permit_params:

permit_params :title, :text, translations_attributes: [:id, :title, :text, :locale]
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top