is how I’d like to format the url that is typed into the url, however,
the problem I am having is how to to convert the query part
(rice-and-cheese) into this (“rice and cheese”)… I’ve tried using gsub
within routes, with no success.
How do you do this in routing? Or does it have to be don by the action
that is handling the query parameter?
Then add a permalink column with a migration and replace the
Recipe.find(params[:id]) with Recipe.find_by_permalink(params[:id]) in
PermalinkFu takes care of converting all the spaces to dashes, as well
as removing other non-word characters and also does a UTF-8 to ascii
translation, so your creme brulée recipe would have a permalink of /
Alternately, assuming that you meant query literally – or if
permalink_fu is too much, then yes. The way to handle it would be in
the Controller or Model rather than in the routes. Probably the
easiest way is to call split("-") on the params[:id] (or whatever your
route supplies) and then do an appropriate find from there.
and have used an application_helper.rb method using gsub to change the
format of the :item or :category parameter in the url and called this
method in my views.
I’m sure that this is not the best way to do it but it does mean
search bots see a different page for every product and category in the
shop and the title of the product or the category is the name of that
page instead of realising that it is one dynamically generated page .
Of corse you can still access the pages without the :category or :item
parameter on the end of the url
I hope this helps and will be checking back to see if any one has any