find() performance

Chad Arimura
Sun, 17 Dec 2006 23:16:59 -0000

I want my application URL''s to have the name of products in the URL as
opposed to the id, like so:

/product/windows+xp instead of /product/view/1
/product/windows+xp/edit instead of /product/edit/1

I assume the best way then would be in the controller to use:

def view
  @product = Product.find_by_name(params[:name])
end

instead of

def view
  @product = Product.find(params[:id])
end


So my question is:

1) Would find_by_name degrade performance significantly because I''m
searching by name now and not by row?

If so, 2) is there a better way to handle the find in a more efficient way
and still use the string name in the URL''s?

Happy holidays,
Chad