I’m almost done a project and only now am I implementing friendly
URLs. I’m using the method from “Simply Rails 2” by Patrick Lenz.
This involves the following addition to the model:
So every time a url is generated it creates a friendly URL.
I’m now having trouble with my controllers though.
if i use @item = Item.find(params[:id]) # Everything works fine.
I have in many spots magick find methods like
@item = Item.find_by_id(params[:id])
@item = Item.find_by_associated_model_id(params[:id])
Which will actually attempt to find the entire friendly URL string as
an ID in the database.
I can fix the problem with
@item = Item.find_by_associated_model_id(params[:id].to_i)
As this will strip the appended string. But I feel theres probably
something I’m missing / a more graceful way.