aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorJavan Makhmali <javan@javan.us>2013-11-14 15:02:05 -0500
committerJavan Makhmali <javan@javan.us>2013-11-14 15:35:53 -0500
commit633100b9e5ab0ca634c86eb56bc2da4f3b33e8c4 (patch)
tree6d3d9a14e89292da97ba0407fcea67d9e34509ab /activerecord/lib/active_record
parent84961dc5df86c70504bdcdc218799e9f848a7a00 (diff)
downloadrails-633100b9e5ab0ca634c86eb56bc2da4f3b33e8c4.tar.gz
rails-633100b9e5ab0ca634c86eb56bc2da4f3b33e8c4.tar.bz2
rails-633100b9e5ab0ca634c86eb56bc2da4f3b33e8c4.zip
Addendum to #12891
* Fix incorrectly named tests * Restore Object#to_param behavior * Ensure param is derived from a squished and truncated string
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