aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-11-14 12:57:46 -0800
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-11-14 12:57:46 -0800
commite15ea62b26e010d02459f8a2438f5a281cc1dd8f (patch)
tree474f2868e00099ec964570d11e68de1a813c3282 /activerecord/lib/active_record
parentf33ab01b7e5d567b7476578515b2f9ac47ca269a (diff)
parent633100b9e5ab0ca634c86eb56bc2da4f3b33e8c4 (diff)
downloadrails-e15ea62b26e010d02459f8a2438f5a281cc1dd8f.tar.gz
rails-e15ea62b26e010d02459f8a2438f5a281cc1dd8f.tar.bz2
rails-e15ea62b26e010d02459f8a2438f5a281cc1dd8f.zip
Merge pull request #12893 from javan/to-param-addendum
Addendum to #12891
Diffstat (limited to 'activerecord/lib/active_record')
-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