Skip to content

Commit

Permalink
Ensure to_param always returns a string
Browse files Browse the repository at this point in the history
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
therubymug authored and Jose Fernandez committed Jan 8, 2009
1 parent 0a55f2d commit 67811d5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/salty_slugs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/slug_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 67811d5

Please sign in to comment.