ActiveAdmin и Globalize gem - PullRequest
       17

ActiveAdmin и Globalize gem

0 голосов
/ 02 мая 2019

Я использую активного администратора в качестве бэк-офиса моего приложения rails.

В форме обновления я отображаю поля внутри вкладки, основываясь на их переводе (мне нужно локали Fr и En). Я также использую гем глобализации

Проблема в том, что когда я пытаюсь отправить форму с неверными данными (не проходя валидацию), activeadmin не отображает сообщения об ошибках для переведенных полей, как это происходит для непереведенных полей ...

Полагаю, это потому, что activeadmin не находит идентификаторы ввода после перевода, но я не знаю, как это исправить

Проект :: LoanRate модель:

 class Project::LoanRate < ApplicationRecord
  extend Enumerize

  belongs_to :project

  has_many :contributions, dependent: :restrict_with_error, foreign_key: :project_loan_rate_id, inverse_of: :loan_rate

  enumerize :restriction_category, in: %i(department city custom opened), predicates: true, scope: true

  translates :restriction_value, :document_description

  # Presence
  validates :restriction_category, :project, presence: true
  validates :rate, :restriction_value, presence: true, unless: :opened?
  validates :document_description, length: {maximum: 50}, presence: true, if: :document_mandatory?

  # Numericality
  validates :rate, :duration, :start_after, numericality: {greater_than_or_equal_to: 0}, allow_nil: true
 end

Разрешенные параметры в activeadmin

permit_params :restriction_category,
                :rate,
                :enabled,
                :start_after,
                :duration,
                :document_mandatory,
                :project_id,
                *Project::LoanRate.translation_params

Форма ActiveAdmin:

active_admin_form_for [:admin, resource] do |f|
  f.inputs t('.general') do
    f.input :enabled
    f.input :project
    f.input :restriction_category
    f.input :rate
    f.input :start_after, hint: t('.days_after_hint')
    f.input :duration
    f.input :document_mandatory, hint: t('.only_custom')
  end

  tabs do
    I18n.available_locales.each do |locale|
      tab locale do
        f.inputs do
          f.localized_input :restriction_value, locale, hint: t('.value_hint_html')
          f.localized_input :document_description, locale, hint: t('.only_mandatory_document')
        end
      end
    end
  end

  f.actions
end

Любая помощь будет принята с благодарностью!

...