如何在Rails中获取link_to输出一个SEO友好的URL? [英] How to get link_to in Rails output an SEO friendly url?

查看:148
本文介绍了如何在Rails中获取link_to输出一个SEO友好的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的link_to标记是:

My link_to tag is:

<%= link_to("My test title",{:controller=>"search", :action=>"for-sale", :id=> listing.id, :title => listing.title, :search_term => search_term}) %>

并生成这个丑陋的网址:

and produces this ugly URL:

http://mysite.com/search/for-sale/12345?title=premium+ad+%2B+photo+%5Btest%5D

如何获得link_to来生成:

How can I get link_to to generate:

http://mysite.com/search/for-sale/listing-title/search-term/12345

尝试过几种不同的方式,在网上找不到多少,真的很感激任何帮助!

Been trying this a few different ways and cannot find much online, really appreciate any help!

推荐答案

看看这个

在你的配置/中添加这个routes.rb

add this in your config/routes.rb

map.connect ':controller/:action/:title/search_item/:id', :controller=>'search', :action=>'for_sale' 

重新启动服务器并检查。
希望有所帮助:)

restart your server and check. Hope that helps :)

这篇关于如何在Rails中获取link_to输出一个SEO友好的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆