<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: friendly_id - Ruby on Rails plugin for human-readable id&#8217;s</title>
	<atom:link href="http://randomba.org/2008/01/friendly_id-ruby-on-rails-plugin-for-human-readable-ids/feed/" rel="self" type="application/rss+xml" />
	<link>http://randomba.org/2008/01/friendly_id-ruby-on-rails-plugin-for-human-readable-ids/</link>
	<description>Programming, Ruby, Rails, and other random things.</description>
	<pubDate>Thu, 20 Nov 2008 22:01:48 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: adrian</title>
		<link>http://randomba.org/2008/01/friendly_id-ruby-on-rails-plugin-for-human-readable-ids/#comment-70</link>
		<dc:creator>adrian</dc:creator>
		<pubDate>Thu, 11 Sep 2008 17:07:29 +0000</pubDate>
		<guid isPermaLink="false">http://randomba.com/?p=23#comment-70</guid>
		<description>@Nash,

Hey, Adrian here.

Sure, please send that patch in!  With Norman we've discussed adding multiple strategies to friendly_id a couple of times in the past.  Recently, we've been playing with top level path names used as ids (a la GitHub) so we're also considering extending friendly_id in that direction (for even friendlier ids). ;-)

Regards</description>
		<content:encoded><![CDATA[<p>@Nash,</p>
<p>Hey, Adrian here.</p>
<p>Sure, please send that patch in!  With Norman we&#8217;ve discussed adding multiple strategies to friendly_id a couple of times in the past.  Recently, we&#8217;ve been playing with top level path names used as ids (a la GitHub) so we&#8217;re also considering extending friendly_id in that direction (for even friendlier ids). <img src='http://randomba.org/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nash</title>
		<link>http://randomba.org/2008/01/friendly_id-ruby-on-rails-plugin-for-human-readable-ids/#comment-69</link>
		<dc:creator>Nash</dc:creator>
		<pubDate>Thu, 11 Sep 2008 16:55:22 +0000</pubDate>
		<guid isPermaLink="false">http://randomba.com/?p=23#comment-69</guid>
		<description>Hi Norman,

  Would you consider a patch for supporting multiple methods instead of one?

  So has_friendly_id would support the following two formats:
  has_friendly_id [:multiple, :methods, :work] and
  has_friendly_id :one_method

  Thanks.


-Nash</description>
		<content:encoded><![CDATA[<p>Hi Norman,</p>
<p>  Would you consider a patch for supporting multiple methods instead of one?</p>
<p>  So has_friendly_id would support the following two formats:<br />
  has_friendly_id [:multiple, :methods, :work] and<br />
  has_friendly_id :one_method</p>
<p>  Thanks.</p>
<p>-Nash</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Norman</title>
		<link>http://randomba.org/2008/01/friendly_id-ruby-on-rails-plugin-for-human-readable-ids/#comment-65</link>
		<dc:creator>Norman</dc:creator>
		<pubDate>Mon, 14 Jul 2008 22:18:13 +0000</pubDate>
		<guid isPermaLink="false">http://randomba.com/?p=23#comment-65</guid>
		<description>OK, I think I'll add it in for now. At least it can make some people happy, as opposed to none. :-)</description>
		<content:encoded><![CDATA[<p>OK, I think I&#8217;ll add it in for now. At least it can make some people happy, as opposed to none. <img src='http://randomba.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Ramalho</title>
		<link>http://randomba.org/2008/01/friendly_id-ruby-on-rails-plugin-for-human-readable-ids/#comment-64</link>
		<dc:creator>David Ramalho</dc:creator>
		<pubDate>Mon, 14 Jul 2008 21:48:30 +0000</pubDate>
		<guid isPermaLink="false">http://randomba.com/?p=23#comment-64</guid>
		<description>no worries, but rails (2.1.0) seems to use the base_class strategy when using STI (that's where I got my problem from) , meaning he will always save the base_class type on polymorphic associations (for some reason), doing the "cast" later on .

But I do understand what you're saying and yes it will happen more often on your example (which is exactly my situation) but I don't know how we can circumvent the Rails situation, I need to understand why it is that they do (or appear to) that

meanwhile, that makes sure you can do Person.find('slug'), Employee.find('slug-slug') and Supervisor.find('slugy-slugy') :)</description>
		<content:encoded><![CDATA[<p>no worries, but rails (2.1.0) seems to use the base_class strategy when using STI (that&#8217;s where I got my problem from) , meaning he will always save the base_class type on polymorphic associations (for some reason), doing the &#8220;cast&#8221; later on .</p>
<p>But I do understand what you&#8217;re saying and yes it will happen more often on your example (which is exactly my situation) but I don&#8217;t know how we can circumvent the Rails situation, I need to understand why it is that they do (or appear to) that</p>
<p>meanwhile, that makes sure you can do Person.find(&#8217;slug&#8217;), Employee.find(&#8217;slug-slug&#8217;) and Supervisor.find(&#8217;slugy-slugy&#8217;) <img src='http://randomba.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Norman</title>
		<link>http://randomba.org/2008/01/friendly_id-ruby-on-rails-plugin-for-human-readable-ids/#comment-63</link>
		<dc:creator>Norman</dc:creator>
		<pubDate>Mon, 14 Jul 2008 21:03:43 +0000</pubDate>
		<guid isPermaLink="false">http://randomba.com/?p=23#comment-63</guid>
		<description>David, this would not allow you to have two different sti classes use the same friendly id.

For example, suppose you want to have something like

class Person &lt; ActiveRecord::Base
end

class Employee &lt; Person
end

class Supervisor &lt; Person
end

@employee = Employee.new(:name =&gt; "John Doe")
@supervisor = Supervisor.new(:name =&gt; "John Doe")

In this case since it uses the base class for the slug, it would not allow you to use "john-doe" for both; the second one is going to be "john-doe-2." 

For some people this would be the desired behavior, for others, I think it would be the opposite. I think ideally friendly_id would provide a way for you to choose the strategy.

I think the best long-term solution is something Adrian Mugnolo proposed to me, which is to make it possible to write your own slug generator class that makes the slugs the way you want them to.</description>
		<content:encoded><![CDATA[<p>David, this would not allow you to have two different sti classes use the same friendly id.</p>
<p>For example, suppose you want to have something like</p>
<p>class Person < ActiveRecord::Base<br />
end</p>
<p>class Employee < Person<br />
end</p>
<p>class Supervisor < Person<br />
end</p>
<p>@employee = Employee.new(:name => &#8220;John Doe&#8221;)<br />
@supervisor = Supervisor.new(:name => &#8220;John Doe&#8221;)</p>
<p>In this case since it uses the base class for the slug, it would not allow you to use &#8220;john-doe&#8221; for both; the second one is going to be &#8220;john-doe-2.&#8221; </p>
<p>For some people this would be the desired behavior, for others, I think it would be the opposite. I think ideally friendly_id would provide a way for you to choose the strategy.</p>
<p>I think the best long-term solution is something Adrian Mugnolo proposed to me, which is to make it possible to write your own slug generator class that makes the slugs the way you want them to.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Ramalho</title>
		<link>http://randomba.org/2008/01/friendly_id-ruby-on-rails-plugin-for-human-readable-ids/#comment-62</link>
		<dc:creator>David Ramalho</dc:creator>
		<pubDate>Mon, 14 Jul 2008 17:07:32 +0000</pubDate>
		<guid isPermaLink="false">http://randomba.com/?p=23#comment-62</guid>
		<description>Ok, got it, the slug finder was not using the base class for the conditions and that was screwing things up

I've edited the following lines on lib/friendly_id.rb and added "base_class" to the arguments ...

139: slugs = Slug.find_by_name_and_sluggable_type(args.first, self.base_class.to_s)

141: slugs = Slug.find_all_by_name_and_sluggable_type(args.first, self.base_class.to_s)</description>
		<content:encoded><![CDATA[<p>Ok, got it, the slug finder was not using the base class for the conditions and that was screwing things up</p>
<p>I&#8217;ve edited the following lines on lib/friendly_id.rb and added &#8220;base_class&#8221; to the arguments &#8230;</p>
<p>139: slugs = Slug.find_by_name_and_sluggable_type(args.first, self.base_class.to_s)</p>
<p>141: slugs = Slug.find_all_by_name_and_sluggable_type(args.first, self.base_class.to_s)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Ramalho</title>
		<link>http://randomba.org/2008/01/friendly_id-ruby-on-rails-plugin-for-human-readable-ids/#comment-61</link>
		<dc:creator>David Ramalho</dc:creator>
		<pubDate>Mon, 14 Jul 2008 15:25:44 +0000</pubDate>
		<guid isPermaLink="false">http://randomba.com/?p=23#comment-61</guid>
		<description>Hey Norman, first of all, great work you did on friendly_id :)

now, how far did you and Keith Pitty go on the STI problem ? I'll look at the code now, but wanted to know if I was repeating any work being currently done :)

again, great work, thanks :)</description>
		<content:encoded><![CDATA[<p>Hey Norman, first of all, great work you did on friendly_id <img src='http://randomba.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>now, how far did you and Keith Pitty go on the STI problem ? I&#8217;ll look at the code now, but wanted to know if I was repeating any work being currently done <img src='http://randomba.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>again, great work, thanks <img src='http://randomba.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Norman</title>
		<link>http://randomba.org/2008/01/friendly_id-ruby-on-rails-plugin-for-human-readable-ids/#comment-58</link>
		<dc:creator>Norman</dc:creator>
		<pubDate>Mon, 23 Jun 2008 19:33:37 +0000</pubDate>
		<guid isPermaLink="false">http://randomba.com/?p=23#comment-58</guid>
		<description>Thanks a lot for that, Robert. I'll try to get that integrated as soon as possible!</description>
		<content:encoded><![CDATA[<p>Thanks a lot for that, Robert. I&#8217;ll try to get that integrated as soon as possible!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Woodward</title>
		<link>http://randomba.org/2008/01/friendly_id-ruby-on-rails-plugin-for-human-readable-ids/#comment-57</link>
		<dc:creator>Robert Woodward</dc:creator>
		<pubDate>Mon, 23 Jun 2008 19:27:58 +0000</pubDate>
		<guid isPermaLink="false">http://randomba.com/?p=23#comment-57</guid>
		<description>Hey,

We ran into the problem of Eager Loading not workin on on the project I work on (http://www.feistypiranha.com) so we decided to fix it up.

I posted the solution that we came up with on our blog (http://www.feistypiranha.com/getting-friendly_id-to-work/).  I have only done limited testing with it, but in theory all parameters should work now...  So you can do :conditions =&#62; "1 = 2", and it will correctly fail (Not return any results.  Since, as far as I know, 1 != 2)

The method we changed was "find_using_friendly_id" in the SluggableClassMethods module.  (Line 127)
And the updated code goes as follows:

      # Finds the record using only the friendly id. If it can't be found
      # using the friendly id, then it returns false. If you pass in any
      # argument other than an instance of String, then it also returns false.
      def find_using_friendly_id(*args)
        return false unless args.first.kind_of?(String)
        slug = Slug.find_by_name_and_sluggable_type(args.first, self.to_s)
        begin
          # Get the class and pass our options
          object_class = Module.const_get(slug.sluggable_type)
          options = args.extract_options!
          return  object_class.find(slug.sluggable_id, options)
        rescue    # The class was bad, use the old slug way
          return false if !slug
          return false if !slug.sluggable
          slug.sluggable.send(:finder_slug=, slug)
          slug.sluggable
        end
      end

Take care everyone, hope this helps!
Robert</description>
		<content:encoded><![CDATA[<p>Hey,</p>
<p>We ran into the problem of Eager Loading not workin on on the project I work on (http://www.feistypiranha.com) so we decided to fix it up.</p>
<p>I posted the solution that we came up with on our blog (http://www.feistypiranha.com/getting-friendly_id-to-work/).  I have only done limited testing with it, but in theory all parameters should work now&#8230;  So you can do :conditions =&gt; &#8220;1 = 2&#8243;, and it will correctly fail (Not return any results.  Since, as far as I know, 1 != 2)</p>
<p>The method we changed was &#8220;find_using_friendly_id&#8221; in the SluggableClassMethods module.  (Line 127)<br />
And the updated code goes as follows:</p>
<p>      # Finds the record using only the friendly id. If it can&#8217;t be found<br />
      # using the friendly id, then it returns false. If you pass in any<br />
      # argument other than an instance of String, then it also returns false.<br />
      def find_using_friendly_id(*args)<br />
        return false unless args.first.kind_of?(String)<br />
        slug = Slug.find_by_name_and_sluggable_type(args.first, self.to_s)<br />
        begin<br />
          # Get the class and pass our options<br />
          object_class = Module.const_get(slug.sluggable_type)<br />
          options = args.extract_options!<br />
          return  object_class.find(slug.sluggable_id, options)<br />
        rescue    # The class was bad, use the old slug way<br />
          return false if !slug<br />
          return false if !slug.sluggable<br />
          slug.sluggable.send(:finder_slug=, slug)<br />
          slug.sluggable<br />
        end<br />
      end</p>
<p>Take care everyone, hope this helps!<br />
Robert</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Norman</title>
		<link>http://randomba.org/2008/01/friendly_id-ruby-on-rails-plugin-for-human-readable-ids/#comment-54</link>
		<dc:creator>Norman</dc:creator>
		<pubDate>Thu, 19 Jun 2008 10:09:02 +0000</pubDate>
		<guid isPermaLink="false">http://randomba.com/?p=23#comment-54</guid>
		<description>@Jim

You can use any method to generate the friendly id, it doesn't just have to be a column. So you coud do something like this:

has_friendly_id :title_and_username, :use_slug =&gt; true

def title_and_username
   "#{user.name}-#{title}"
end</description>
		<content:encoded><![CDATA[<p>@Jim</p>
<p>You can use any method to generate the friendly id, it doesn&#8217;t just have to be a column. So you coud do something like this:</p>
<p>has_friendly_id :title_and_username, :use_slug => true</p>
<p>def title_and_username<br />
   &#8220;#{user.name}-#{title}&#8221;<br />
end</p>
]]></content:encoded>
	</item>
</channel>
</rss>
