Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix to_param when attribute has multibyte character

  • Loading branch information...
commit ee738f960439e511285bc53b7207cebacda8db36 1 parent 7b5cf7e
@rono23 rono23 authored
View
6 activerecord/lib/active_record/integration.rb
@@ -98,8 +98,10 @@ def to_param(method_name = nil)
super()
else
define_method :to_param do
- if (default = super()) && (result = send(method_name).to_s).present?
- "#{default}-#{result.squish.truncate(20, separator: /\s/, omission: nil).parameterize}"
+ if (default = super()) &&
+ (result = send(method_name).to_s).present? &&
+ (param = result.squish.truncate(20, separator: /\s/, omission: nil).parameterize).present?
+ "#{default}-#{param}"
else
default
end
View
6 activerecord/test/cases/integration_test.rb
@@ -46,6 +46,12 @@ def test_to_param_class_method_squishes
assert_equal '4-ab-ab-ab-ab-ab-ab', firm.to_param
end
+ def test_to_param_class_method_multibyte_character
+ firm = Firm.find(4)
+ firm.name = "戦場ヶ原 ひたぎ"
+ assert_equal '4', firm.to_param
+ end
+
def test_to_param_class_method_uses_default_if_blank
firm = Firm.find(4)
firm.name = nil
Please sign in to comment.
Something went wrong with that request. Please try again.