Search code examples
ruby-on-railsrubyactiveadminrails-i18nglobalize

Rails 4.2.4 ActiveAdmin Globalize show one input only


Here I have a problem when using rails 4.2.4 + activeadmin 0.6.6 + rails-i18n 4.0.8 + globalize 4.0.3 + activeadmin-globalize 1.0.0 . The problem I am facing is shown in the following image, it only show one input box for me:

There is only textarea input for content In the contact table, I should have more variables as below:

db/migrate/XXXXXXXXX_create_contacts.rb

class CreateContacts < ActiveRecord::Migration
  def up
    create_table :contacts do |t|

     t.string :url
     t.boolean :publish, :default => false
     t.integer :sequence
     t.timestamps null: false
    end
  end

  def down
    drop_table :contacts
  end
end

db/migrate/XXXXXXXXX_translate_for_contacts.rb

class TranslateForContact < ActiveRecord::Migration
  def up
    Contact.create_translation_table! :tool => :string, :content => :text
  end

  def down
    Contact.drop_translation_table!
  end
end

Contact table is originally generated using scaffold.
:url, :publish, :sequence are the variables common in all locales.
Only :tool and :content need to translate.

In app/models/contact.rb

class Contact < ActiveRecord::Base
  active_admin_translates :tool, :content do
    validates_presence_of :tool, :content
  end
  translates :tool, :content
end

In app/admin/contact.rb

ActiveAdmin.register Contact do

  permit_params :url, :tool, :content, :publish, :sequence, translations_attributes: [:id, :locale, :tool, :content]

  index do
    translation_status
    default_actions
  end

  form do |f|
    f.translated_inputs "Translated fields", switch_locale: false do |t|
      t.input :tool
      t.input :content
    end
    f.actions
  end

end

One more related thing, as I have also facing the "missing form_buffers" problem, I have edited the code in the activeadmin-globalize gem as following webpage:
https://github.com/maxime-carbonneau/activeadmin-globalize/commit/734f375152982ccde12e7810760a7ab82c8d4a20
but I am not sure if this edit will cause the problem.

Before I install and use activeadmin-globalize, I am sure there are the input boxes for :url, :publish, :sequence.
Do anyone have the solution or know what's happened? Thanks!

----------------Final Solution--------------------
As activeadmin-globalize is not maintained, most of it function not work normally. I recommend using another gem for it.


Solution

  • In the docs for the activeadmin-globalize gem, the author on Dec 9, 2014 warned users that he's not maintaining the gem anymore and to take it as you will. You may want to consider dropping the gem.

    But, as activeadmin is concerned, I believe the reason your not seeing any other form inputs on your page is because you have haven't included them in your code below

    # app/admin/contact.rb
    ...
    form do |f|
      f.translated_inputs "Translated fields", switch_locale: false do |t|
        t.input :tool
        t.input :content
      end
      f.actions
    end
    

    If you want to include them back in you will either need to just remove that entire block of code altogether and let activeadmin create the default form inputs for you or you can individually add your inputs back in

    # app/admin/contact.rb
    ...
    form do |f|
      f.translated_inputs "Translated fields", switch_locale: false do |t|
        t.input :url
        t.input :tool
        t.input :content
        t.input :publish
        ...
      end
      f.actions
    end