提交 4779aaa1 编写于 作者: R Rafael Mendonça França

Merge pull request #13386 from rono23/fix-to-param

Fix to_param when attribute has multibyte character
......@@ -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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册