Skip to content
Browse files

Ensure to_param always returns a string

URL helpers assume to_param returns a string and raise a type error if
this is not true.

Signed-off-by: Jose Fernandez <jose@umn.edu>
  • Loading branch information...
1 parent 0a55f2d commit 67811d5a26527d38bd8b118b109b01af10dc0d8b @therubymug therubymug committed with Jose Fernandez Jan 9, 2009
Showing with 3 additions and 1 deletion.
  1. +1 −1 lib/salty_slugs.rb
  2. +2 −0 test/slug_test.rb
View
2 lib/salty_slugs.rb
@@ -63,7 +63,7 @@ def sluggify(text)
module InstanceMethods
def to_param
- return self.id if slug_prepend_id && self[slug_column].blank?
+ return self.id.to_s if slug_prepend_id && self[slug_column].blank?
slug_prepend_id ? "#{self.id}-#{self[slug_column]}" : self[slug_column]
end
end
View
2 test/slug_test.rb
@@ -74,6 +74,8 @@ def test_sync_slug
def test_to_param
assert_equal @post.to_param, "#{@post.id}-#{@post[Post.slug_column]}"
assert_equal @product.to_param, "#{@product[Product.slug_column]}"
+ post_with_blank_slug = Post.create
+ assert_equal post_with_blank_slug.to_param, post_with_blank_slug.id.to_s
end
def test_sluggify

0 comments on commit 67811d5

Please sign in to comment.
Something went wrong with that request. Please try again.