aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/integration.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/integration.rb')
-rw-r--r--activerecord/lib/active_record/integration.rb16
1 files changed, 10 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/integration.rb b/activerecord/lib/active_record/integration.rb
index f881fa74b2..951db5b756 100644
--- a/activerecord/lib/active_record/integration.rb
+++ b/activerecord/lib/active_record/integration.rb
@@ -86,12 +86,16 @@ module ActiveRecord
#
# params[:id] # => "123-fancy-pants"
# User.find(params[:id]).id # => 123
- def to_param(method_name)
- define_method :to_param do
- if (default = super()) && (result = send(method_name).to_s).present?
- "#{default}-#{result.truncate(20, separator: /\s/, omission: nil).parameterize}"
- else
- default
+ def to_param(method_name = nil)
+ if 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}"
+ else
+ default
+ end
end
end
end