Reputation: 1159
I'm ussing activeadmin (1.0.0.pre2).
In my model, I have fields, filled with tags. I translate this tags in the app using the method "translate_name" in form field values (like this .. i18n for select boxes)
In activeadmin I'm using custom form to choose only some fields.
This is my activeadmin code...
index do
column :user
column :user_surname
column :service
column :patient_type
column :description
actions
end
form do |f|
if f.object.errors.size >= 1
f.inputs "Errors" do
f.object.errors.full_messages.join('|')
end
end
f.semantic_errors # shows errors on :base
f.inputs :user
f.inputs :service
f.inputs :patient_type
f.inputs :postal_code
f.inputs :availability
f.inputs :date
f.inputs :estimated_period
f.inputs :description
f.actions # adds the 'Submit' and 'Cancel' buttons
end
service y patient_type are nested resources exactly like this ActiveAdmin customizing the form for belongs_to
activeadmin don't traslate this tags.
Any idea to solve this?
Thanks.
Upvotes: 0
Views: 883
Reputation: 3363
In Formtastic you can define a to_label
method on your models which will be
used when rendering the select field options. Also, ActiveAdmin will call a
variety of methods when searching for a name for your object, like
display_name
. See Index as a Table docs.
Adding to_label
and display_name
methods to your Service class should
properly translate the values highlighted above:
class Service < ActiveRecord::Base
def translated_name
I18n.t(name)
end
# method used when creating Formtastic select options
def to_label
translated_name
end
# method used for displaying model names in ActiveAdmin
def display_name
translated_name
end
end
ActiveAdmin checks objects for the following methods to show a name. Most often
the name
method is used.
display_name
full_name
name
username
login
title
email
to_s
Upvotes: 1