I remember reading somewhere a tip on improving your search engine
ranking, by forming URLs that included relevant text, e.g. www.domain.com/article/man_eats_hat. In the rails app that I’m writing,
I’ve noticed I can set this up very easily by appending the post title
(after downcase.split.join(‘_’)) to the post link. So, Sooma
can easily also be Sooma, with the following
added to config/routes.rb:
map.connect ‘:controller/:action/:id/*anything’
Of course this also means that Sooma points to
the same place, and I was wondering if this could be considered as bad
practice.
Of course this also means that blog.com/posts/4/anything_else points to
the same place, and I was wondering if this could be considered as bad
practice.
You could just have a url version of your blog title in the db. You can
then just have your urls like this:
/posts/my_blog_title/ rather than including the id.
I’ve written a plugin called ‘url_column’ that will maintain a url in
the table from a specified column automatically on saves and updates.
For example, you can do:
class Post < ActiveRecord::Base
url_column :post_url, :from => :title
end
Whenever you save or create a post it’ll automatically ‘urlify’ the post
title and update the post_url column.
Very nice. My only suggestion would be to call it
permalink_column instead of url_column.
Hmm… good sugguestion - but it’s not really specifically for permenant
links. It’ll will be updated if, say, the title of the page changes.
In that respect it can be used for categories, pages, products -
whatever.
Nice! Does it handle non-ASCII in UTF-8?
It uses basic Ruby replaces. I’ve not really tried it with anything
more complex than the examples and tests - try it out and let me know
:0)
Steve
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.