norman/friendly_id — Issue #248: Slugs that start with a number are casted to an int in find()
Author: christophermanning
Created: 2012-02-29 18:13:23+00:00
State: open

I have slugs that may start with a number: 8abcdef and instead of finding the record with slug '8abcdef', it finds the record with the id of 8 since '8abcdef'.to_i == 8

When running

MyModel.find(params[:id])

these queries are ran

MyModel Load (85.6ms) SELECT "my_model".* FROM "my_model" WHERE "my_model"."slug" = '8abcdef' LIMIT 1
MyModel Load (0.4ms) SELECT "my_model".* FROM "my_model" WHERE "my_model"."id" = $1 LIMIT 1 [["id", "8abcdef"]]

and it returns a record with the id of 8 instead of the record that matches the slug

This works as expected

MyModel.where(:slug => params[:id]).first!

I didn't see anything in the docs (http://rubydoc.info/github/norman/friendly_id/master/FriendlyId/Slugged, etc) that mentions this gotcha.

I am using:

pg (0.13.2)
rails (3.2.1)
friendly_id (4.0.1)

MyModel.rb

class MyModel < ActiveRecord::Base
extend FriendlyId
friendly_id :slug