fabn / activeadmin-globalize

Provides translation UI for ActiveAdmin and Globalize gems
https://github.com/fabn/activeadmin-globalize
MIT License
30 stars 54 forks source link

Empty translation created without adding it in the UI #1

Open besi opened 10 years ago

besi commented 10 years ago

I did run into an issue but there was no issue tracker enabled on the repo:

The original plugin did that as well which I think is the reason for a problem that I am running into on production environment: See https://github.com/globalize/globalize/issues/362

fabn commented 10 years ago

I can't reproduce this in the dummy app bundled in this repository, could you try to do that? Are you still experiencing the issue using the latest version from develop branch?

Quick setup:

git clone https://github.com/fabn/activeadmin-globalize.git
cd spec/dummy
RAILS_ENV=production rake db:migrate
# Change config.serve_static_assets = true in config/environments/production.rb
# Change config.i18n.default_locale = :de in config/application.rb
# You can apply the patch below with patch -n1 < config.patch
rake assets:precompile RAILS_ENV=production
rails s -e production
# open http://localhost:3000/admin and login with devise default credentials, user: admin@example.com, pass: password

When I create an article in the above setup I get these logs

I, [2014-09-24T17:33:48.613070 #82049]  INFO -- : Started POST "/admin/articles" for 127.0.0.1 at 2014-09-24 17:33:48 +0200
I, [2014-09-24T17:33:48.614374 #82049]  INFO -- : Processing by Admin::ArticlesController#create as HTML
I, [2014-09-24T17:33:48.614491 #82049]  INFO -- :   Parameters: {"utf8"=>"✓", "authenticity_token"=>"BqPYcHG1vKP18da61/vhpkuJEpxBRz7CnJMcjkzfx5M=", "article"=>{"translations_attributes"=>{"0"=>{"locale"=>"de", "id"=>"", "title"=>"Article Title in German", "body"=>"Test Article"}}}, "commit"=>"Article anlegen"}

And only de version of article is created.

Here are the gems I'm using

bundle show
  * activeadmin (1.0.0.pre 930d34c)
  * activeadmin-globalize (1.0.0.pre)
  * globalize (4.0.2)
  * rails (4.0.10)

Could you try to reproduce the issue in the dummy app? If you can't I need more details, at least

Here is the patch with changes above to run the app in production, apply it with patch -p1 < input.patch

diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb
index 24dbd4b..7f73038 100644
--- a/spec/dummy/config/application.rb
+++ b/spec/dummy/config/application.rb
@@ -19,7 +19,7 @@ module Dummy

     # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
     # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
-    config.i18n.default_locale = :en
+    config.i18n.default_locale = :de
     config.i18n.available_locales = [:de, :en, :hu, :it, :'pt-BR', :'pt-PT']

   end
diff --git a/spec/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb
index b690b1c..20410c1 100644
--- a/spec/dummy/config/environments/production.rb
+++ b/spec/dummy/config/environments/production.rb
@@ -20,7 +20,7 @@ Dummy::Application.configure do
   # config.action_dispatch.rack_cache = true

   # Disable Rails's static asset server (Apache or nginx will already do this).
-  config.serve_static_assets = false
+  config.serve_static_assets = true

   # Compress JavaScripts and CSS.
   config.assets.js_compressor = :uglifier
besi commented 10 years ago

Thanks for the detailed instructions and sorry for not being specific. I can't reproduce the issue in the demo app. I wanted to adapt it to my project, but there is no Gemfile (?).

bundle show:

Gems included by the bundle:
  * actionmailer (4.0.4)
  * actionpack (4.0.4)
  * activeadmin (1.0.0.pre 40ac665)
  * activeadmin-globalize (1.0.0.pre 0bdb3d2)
  * activeadmin-sortable (0.0.3)
  * activemodel (4.0.4)
  * activerecord (4.0.4)
  * activerecord-deprecated_finders (1.0.3)
  * activesupport (4.0.4)
  * acts_as_list (0.4.0)
  * arbre (1.0.2)
  * arel (4.0.2)
  * bcrypt (3.1.7)
  * better_errors (1.1.0)
  * binding_of_caller (0.7.2)
  * bourbon (3.2.3)
  * builder (3.1.4)
  * bundler (1.7.3)
  * capistrano (3.2.1)
  * capistrano-bundler (1.1.2)
  * capistrano-rails (1.1.1)
  * choice (0.1.6)
  * coderay (1.1.0)
  * coffee-rails (4.0.1)
  * coffee-script (2.2.0)
  * coffee-script-source (1.7.0)
  * countries (0.9.3)
  * country_select (1.3.1)
  * currencies (0.4.2)
  * daemons (1.1.9)
  * debug_inspector (0.0.2)
  * devise (3.2.4)
  * diff-lcs (1.2.5)
  * erubis (2.7.0)
  * eventmachine (1.0.3)
  * execjs (2.0.2)
  * formtastic (3.0.0)
  * globalize (4.0.2)
  * globalize-versioning (0.1.0.alpha.1)
  * has_scope (0.6.0.rc)
  * hike (1.2.3)
  * i18n (0.6.11)
  * inherited_resources (1.4.1)
  * jbuilder (1.5.3)
  * jquery-rails (3.1.0)
  * jquery-ui-rails (5.0.0)
  * json (1.8.1)
  * kaminari (0.16.1)
  * kgio (2.9.2)
  * mail (2.5.4)
  * mime-types (1.25.1)
  * mini_portile (0.5.3)
  * minitest (4.7.5)
  * multi_json (1.9.2)
  * mysql2 (0.3.13)
  * net-scp (1.2.1)
  * net-ssh (2.9.0)
  * nokogiri (1.6.1)
  * orm_adapter (0.5.0)
  * paper_trail (3.0.2)
  * pg (0.17.1)
  * polyamorous (1.1.0)
  * polyglot (0.3.4)
  * rack (1.5.2)
  * rack-test (0.6.2)
  * rails (4.0.4)
  * rails-erd (1.1.0)
  * rails_12factor (0.0.2)
  * rails_serve_static_assets (0.0.2)
  * rails_stdout_logging (0.0.3)
  * railties (4.0.4)
  * raindrops (0.13.0)
  * rake (10.2.2)
  * ransack (1.4.1)
  * rdoc (4.1.1)
  * redcarpet (3.1.2)
  * responders (1.0.0)
  * rspec-core (3.0.3)
  * rspec-expectations (3.0.3)
  * rspec-mocks (3.0.3)
  * rspec-rails (3.0.2)
  * rspec-support (3.0.3)
  * ruby-graphviz (1.0.9)
  * rubyXL (2.5.3)
  * rubyzip (1.1.3)
  * sass (3.2.19)
  * sass-rails (4.0.3)
  * sdoc (0.4.0)
  * select2-rails (3.5.9)
  * simple_form (3.0.2)
  * slim (2.0.2)
  * slim-rails (2.1.3)
  * sprockets (2.11.0)
  * sprockets-rails (2.0.1)
  * sqlite3 (1.3.9)
  * sshkit (1.4.0)
  * temple (0.6.7)
  * term-ansicolor (1.3.0)
  * thin (1.6.1)
  * thor (0.19.1)
  * thread_safe (0.3.3)
  * tilt (1.4.1)
  * tins (1.2.0)
  * treetop (1.4.15)
  * turbolinks (2.2.2)
  * twitter-bootstrap-rails (3.1.1 1d93c5a)
  * tzinfo (0.3.39)
  * uglifier (2.5.0)
  * unicorn (4.8.2)
  * warden (1.2.3)
  * yaml_db (0.2.3 fb4b6bd)

POST request when creating a programme:

utf8    ✓
authenticity_token  VL2ZSmY0AaMYm7rV7VZIK8PJcYxr4gOlwbAkX+9oxoo=
programme[translations_attributes][0][locale]   de
programme[translations_attributes][0][id]   
programme[translations_attributes][0][title]    title
programme[translations_attributes][0][summary]  summary
programme[translations_attributes][0][description]  
programme[translations_attributes][0][detailed_description] 
programme[translations_attributes][0][deadline_info]    
programme[translations_attributes][0][budget]   
programme[translations_attributes][0][duration] 
programme[translations_attributes][0][application_info] 
programme[translations_attributes][0][contact]  
programme[category_ids][]   
programme[category_ids][]   2
programme[level_ids][]  
programme[level_ids][]  5
programme[fund_type_ids][]  
programme[fund_type_ids][]  4
programme[nationality_ids][]    
programme[nationality_ids][]    
programme[destination_ids][]    
programme[destination_ids][]    
programme[region_id]    
programme[deadlines_string] 
programme[contact_point_id] 
programme[website]  http://google.com
programme[admin_contact]    admin@domain.com
programme[followup] 
programme[admin_remarks]    
programme[updated_by]   admin@domain.com
programme[visible]  0
programme[visible]  1
commit  Create Programme

It looks like there is no English form data sent to the server. However the duplicate language is created though (See updated screenshots in the issue description).

My production.rb:

  # ...
  config.i18n.fallbacks = true

My application.rb

    # ...
    config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    config.i18n.available_locales = [:de, :en]
    config.i18n.fallbacks = true
    config.i18n.enforce_available_locales = true
    config.i18n.default_locale = :de
fabn commented 10 years ago

I read the linked issue in globalize gem and they marked your report as a bug. Maybe it's involved here?

Could you try to execute this code using rails console and see if the english version is created as well?

your_attrs = {not_translated: 'field'} # your base fields with no need for translations
de_translation = {
  locale: :de,
  title: 'title',
  summary: 'summary',
  # ...
}
Programme.create!(your_attrs.merge(translations_attributes: [de_translation]))

The embedded dummy application it uses main Gemfile and gemspec. Notice there is no Gemfile.lock in the repository.

besi commented 10 years ago

I did this but only the German translation was created:

your_attrs = {
    website: 'http://google.com',
    admin_contact: 'bubu@example.com',
    levels: [Level.last],
    categories: [Category.last],
    fund_types: [FundType.last],
}
de_translation = {
    title: 'title',
    summary: 'summary'
}

Programme.create!(your_attrs.merge(translations_attributes: [de_translation]))

screen shot 2014-09-25 at 16 14 28

fabn commented 10 years ago

Can you launch a pry session on create and use it to explore the created object? You can do that by overwriting the create action in this way:

# In your AA resource file
controller do
  create! do |format|
    binding.pry # Your object is available in resource (or @programme)
    format.html { redirect_to resource }
  end
end

Another interesting thing to see would be the full SQL output for the create action.

jtomaszewski commented 7 years ago

IMHO Propably this whole issue comes down to https://github.com/fabn/activeadmin-globalize/pull/17 and https://github.com/globalize/globalize/pull/328 .