Skip to content

Commit 04aada7

Browse files
ebeigartsgregbell
authored andcommitted
Fixed I18n labels with Formtastic 2.0
1 parent 0f515a0 commit 04aada7

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/active_admin/inputs/filter_base.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ def collection_from_options
2929

3030
# Returns the default label for a given attribute
3131
# Will use ActiveModel I18n if possible
32-
def default_filter_label(method)
33-
if @object.base.respond_to?(:human_attribute_name)
34-
@object.base.human_attribute_name(method)
32+
def humanized_method_name
33+
if object.base.respond_to?(:human_attribute_name)
34+
object.base.human_attribute_name(method)
3535
else
36-
method.to_s.titlecase
36+
method.to_s.send(builder.label_str_method)
3737
end
3838
end
3939

spec/unit/filter_form_builder_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ def filter(name, options = {})
5656
it "should label a text field with search" do
5757
body.should have_tag('label', 'Search Title')
5858
end
59+
60+
it "should translate the label for text field" do
61+
begin
62+
I18n.backend.store_translations(:en, :activerecord => { :attributes => { :post => { :title => "Name" } } })
63+
body.should have_tag('label', 'Search Name')
64+
ensure
65+
I18n.backend.reload!
66+
end
67+
end
5968
end
6069

6170
describe "text attribute" do

0 commit comments

Comments
 (0)