+1 for friendly_id as per ruby-toolbox.com
I'm using it on my current project
ie.
class Sport < ActiveRecord::Base
has_friendly_id :name, :use_slug => true
..
class League
has_friendly_id :name, :use_slug => true, :scope => :locale
..
class Team < ActiveRecord::Base
has_friendly_id :name, :u
class Product < AR::Base
def to_param
"#{self.id} #{self.name_or_other_string}".parameterize
end
end
On Nov 2, 1:52 pm, Aymeric Gaurat-Apelli
wrote:
> Don't you need a dash? Is the space character enough?
>
> def to_param
> "#{id}*-*#{name_or_other_string}"
> end
>
> Cheers,
>
> Aymer
Don't you need a dash? Is the space character enough?
def to_param
"#{id}*-*#{name_or_other_string}"
end
Cheers,
Aymeric
On Tue, Nov 2, 2010 at 1:40 PM, Bayan Khalili wrote:
> Hi,
>
> How about this?
>
> class Product < AR::Base
> def to_param
>"#{self.id} #{self.name_or_other_string
Ah crap, I forgot to add 'parameterize' to my code.
Regards,
Bayan
On Nov 2, 8:38 am, Bodaniel Jeanes wrote:
> Matt,
>
> This has always been easy in rails. All you have to do is define the
> `to_param` method on your model.
>
> E.g.
>
> class Product < AR::Base
> def to_param
> "perhaps-p
Hi,
How about this?
class Product < AR::Base
def to_param
"#{self.id} #{self.name_or_other_string}"
end
end
This way, you don't need to replace your controller code to cater for
this, you still get to search on the index id field, and you don't run
into duplicate values where 'name_or_ot