unmantained-activeadmin-plugins / activeadmin-globalize

MIT License
51 stars 188 forks source link

Updating record creates new translation records instead of updating them #33

Open martin-macak opened 10 years ago

martin-macak commented 10 years ago

I have simple application like this

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 try to update record, new translation records are created instead updating the old ones causing the AA to display the first value.

I also posted this as a question on Stack Overflow at http://stackoverflow.com/questions/23547401/activeadmin-globalize-does-not-update-records

dtengeri commented 10 years ago

You have to add :id to translations_attributes at permit_params:

permit_params :title, :text, translations_attributes: [:id, :title, :text, :locale]
micred commented 10 years ago

@dtengeri you save my morning. Guys please update Getting started guide! Now I have messed up translation table with duplicates (and I wonder why globalize did not add unique index on [id, locale])

olivictor commented 10 years ago

Same problem here. Thanks a lot! Please update the Getting started guide! In my case that mysteriously happened only on production env.