Hi all
I want to implement url aliasing on my site...say suppose my url is
domain/blog/1 instead of that i want domain/blog/title-of-that-blog Is there any method how i can remove Id and put the title instead
Thanks a lot
Dhaval Parikh
Hi all
I want to implement url aliasing on my site...say suppose my url is
domain/blog/1 instead of that i want domain/blog/title-of-that-blog Is there any method how i can remove Id and put the title instead
Thanks a lot
Dhaval Parikh
Dhaval Parikh wrote:
Hi all
I want to implement url aliasing on my site...say suppose my url is
domain/blog/1 instead of that i want domain/blog/title-of-that-blog Is there any method how i can remove Id and put the title instead
Thanks a lot
Dhaval Parikh
You will have to create a slug or a permalink column in your e.g. Article model, make sure it is unique, then you have a route like #routes.rb map.article 'blog/:permalink' , :controller=>'article', :action=>'show' #article_controller.rb def show @article = Article.find_by_permalink(params[:permalink]) render :template => 'not_found', :status => 404 unless @article end
but in that case i need to route for each and every controller and its methods..which i dont want...
I think you can do something like
map.resources ':controller/:action/:permalink' , :controller=>':controller', :action=>':action',
and optionally maybe even :id => :permalink. I don't know about if and where you should put the quotes, if any, though.