diff options
author | Matthew Draper <matthew@trebex.net> | 2016-07-09 07:14:26 +0930 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-09 07:14:26 +0930 |
commit | 4e961ca184d39bcc3755d017e94bf03c6e656b29 (patch) | |
tree | 34cf9e4e67ca8a59ba78111fb5c6881c8993b579 /activerecord/lib | |
parent | c62ac07be86a747f9b40ad25f60003e4f6022d26 (diff) | |
parent | 3b49d792231f8051a82cee37c46ac5b23de844db (diff) | |
download | rails-4e961ca184d39bcc3755d017e94bf03c6e656b29.tar.gz rails-4e961ca184d39bcc3755d017e94bf03c6e656b29.tar.bz2 rails-4e961ca184d39bcc3755d017e94bf03c6e656b29.zip |
Merge pull request #23636 from rab/fix-to_param-truncation
fix to_param to maximize content
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/integration.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/integration.rb b/activerecord/lib/active_record/integration.rb index 466c8509a4..d729deb07b 100644 --- a/activerecord/lib/active_record/integration.rb +++ b/activerecord/lib/active_record/integration.rb @@ -86,7 +86,7 @@ module ActiveRecord # # user = User.find_by(name: 'David Heinemeier Hansson') # user.id # => 125 - # user_path(user) # => "/users/125-david" + # user_path(user) # => "/users/125-david-heinemeier" # # Because the generated param begins with the record's +id+, it is # suitable for passing to +find+. In a controller, for example: @@ -100,7 +100,7 @@ module ActiveRecord define_method :to_param do if (default = super()) && (result = send(method_name).to_s).present? && - (param = result.squish.truncate(20, separator: /\s/, omission: nil).parameterize).present? + (param = result.squish.parameterize.truncate(20, separator: /-/, omission: '')).present? "#{default}-#{param}" else default |