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

translated_inputs - only last input is rendered #4

Open ghost opened 9 years ago

ghost commented 9 years ago

Thank you for the new version in the develop branch. I've tested it now and it seems to work except for one issue:

When generating a form like the following:

f.translated_inputs "General", switch_locale: true do |t| t.input :description t.input :name end

Only the first t.input is rendered. The second is ignored.

Could you please have another look into this. Thank you!

fabn commented 9 years ago

So, you're having inputs for all locales for name field and description input is completely misssing?

fabn commented 9 years ago

Also, what happens if you add another field to that block?

ghost commented 9 years ago

No, only the :desciption field is rendered. The :name field is completely missing. (see attached screenshot) screenshot

If I make :name the first field, only :name is rendered and :description is missing.

ghost commented 9 years ago

I've tested it now with 3 fields in different positions. Every time, only the last field is rendered.

fabn commented 9 years ago

That's interesting, because if the rendered field is the last one I have an idea of what is happening. It's like when you're using arbre with rails helpers as in

li { 3.times { |i| link_to(i, '#')  } } # this will show only last link
li { 3.times { |i| text_node link_to(i, '#')  } } # this will show all links

In original report you're saying that the shown input is the first one and with 3 inputs only last is rendered, is that correct?

ghost commented 9 years ago

Sorry, I mixed that up in my first report. I've double checked it now: it's always the last input that is shown, so your idea seems to be correct...

fabn commented 9 years ago

I've updated AA to the latest github version and I'm not able to reproduce your issue. There is a tested resource which should resemble your configuration and with the latest AA and formtastic the issue does not happen. Could you post your AA and formtastic exact versions from bundle show output?

Also native has_many method in AA should have a similar behavior and I found this recent commit in AA which changes that method. I reproduced that commit in translated_inputs code, could you try to run your code against that commit and see if it works?

gem 'activeadmin-globalize', '~> 1.0.0.pre', github: 'fabn/activeadmin-globalize', branch: 'test-fix'
ghost commented 9 years ago

I've tried the test-fix branch without success. The issue remains.

Gems included by the bundle:

ghost commented 9 years ago

I've tried several versions now but also the test-fix branch does not work for me. I tried to set up a complete new project to test it but without success. Everytime, only the last t.input is rendered.

For the moment, I ended up doing something like

      f.input :name_de
      f.input :name_en
      f.input :description_de
      f.input :description_en

with the globalize-accessors gem.

Do you have any solution yet?

fabn commented 9 years ago

I wasn't able to reproduce your issue yet. I have a couple of apps running this code and both run fine. Also the embedded test application works.

If you have a full project which reproduce the issue please share it on github and I'll try to work on this issue as soon as I have some spare time. A minimal new rails app with the issue would be enough to try to fix this.

ghost commented 9 years ago

Finally I have a trace now:

In a clean new project, when I do something like

  form do |f|
    f.semantic_errors # shows errors on :base

    f.inputs 'General' do
      f.input :name
    end

    f.translated_inputs "Details", switch_locale: true do |t|
      t.input :description
      t.input :interests
      t.input :presets
    end

     f.actions

  end

there is no problem. But when I reverse the two sections, namely:

  form do |f|
    f.semantic_errors # shows errors on :base

    f.translated_inputs "Details", switch_locale: true do |t|
      t.input :description
      t.input :interests
      t.input :presets
    end

    f.inputs 'General' do
      f.input :name
    end

     f.actions

  end

the problem described arises.

So, only when f.translated_inputs is the first item in the form the issue exists.

fabn commented 9 years ago

@gerdhuebscher sorry for a such long time to answer. I was finally able to reproduce the issue. The issue happens only when f.translated_inputs is used at top level element for the form. Could you wrap your fields into a f.inputs block?

    f.inputs 'Details' do
      f.translated_inputs "Details", switch_locale: true do |t|
        t.input :description
        t.input :interests
        t.input :presets
      end
    end

P.S. Latest develop is tested now against released activeadmin. I'll try to fix the issue and to clean the api to use it as in your example.

tobsch commented 6 years ago

any progress, @mauriciopasquier :) ?