Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
martin-macak opened this issue May 8, 2014 · 3 comments

Comments

@martin-macak
Copy link

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
Copy link

dtengeri commented May 8, 2014

You have to add :id to translations_attributes at permit_params:

permit_params :title, :text, translations_attributes: [:id, :title, :text, :locale]

@micred
Copy link

micred commented Jun 6, 2014

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants