Question

I have a site that currently has URLS that look like this

http://localhost:3000/public/category/1?category_id=1

That the SEO guy has requested be changed to this

http://localhost:3000/(:category_name)-leasing

where (:category_name) is the name of the category referenced by category_id=1 and is appended with "-leasing"

Is it possible to set this up without creating a new column in my category model for a permalink.

Currently I also have this in my routes.rb file:

get ':permalink', :to => 'public#show'

which displays items from the category mentioned above as

http://localhost:3000/item-name-from-permalink

Is this going to prevent a category using the same url structure? will rails be able to distinguish between a :permalink and a (:category_name)-leasing url or will the url need to something like:

http://localhost:3000/category/(:category_name)-leasing

Thanks in advance

Was it helpful?

Solution

class Category < ActiveRecord::Base

  def to_param
    "#{self.id}-#{self.title.parameterize}"
  end

end

will produce url like http://localhost:3000/categories/1-some-good-title

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top