If I have a Post model of ID 1,
I can access this resource by
http://localhost:3000/posts/1
but weired thing is that when I use these URL, I can get the same result.
http://localhost:3000/posts/1somethingweird-blah-blah-blah-idont-like-this
How can I prevent this?
This is likely because
params[:id]is being converted from aStringto anintand in Ruby calling"1somethingweird-blah-blah-blah-idont-like-this".to_iwill actually result in1.You can fix this at the route level: