Re: find() performance

sness
Mon, 18 Dec 2006 05:44:08 -0000

A nice way to do this is to use the acts_as_sluggable plugin:

http://www.agilewebdevelopment.com/plugins/acts_as_sluggable
http://dev.2750flesk.com/acts_as_sluggable/

You can then use it in your model like this:

 class Article < ActiveRecord::Base

    acts_as_sluggable :with => ''title''

  end

A link in your view would be:

link_to ''Read article'', :action =>
''show'', :id => @article

And the URL it generates would look like:

/articles/show/76-omg-my-cat-is-so-cute-lol

I''m using acts_as_sluggable in a couple different Rails applications
and it''s working very nicely for me, a live example is:

http://www.lovemygarden.net/resources/article/1-testing-and-amending-garden-soil

yours,
sness.
http://www.sness.net


On 12/17/06, Charles Lowe
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:
>
> askegg wrote:
> > That seems like a reasonable approach to me, assuming you configure
the
> > routes accordingly.
> > Performance will be slower due to the nature of the search, but not by
> > much.  I would suggest dropping an index onto the name field.
>
> I''ve forgotten where I saw the post, but it recommended taking the
> approach of including the id and the name (which can change). In fact
> the name can be arbitrary and can be ignored. ie, allow
>
> /product/1-windows+xp/edit
> /product/2-windows+98
>
> etc.
>
> Then you just ignore the non-id part, and have no performance problems,
> and the urls will still work if you rename the product.
>
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >