如何在 Rails 3 中生成带有斜杠的链接? [英] How to generate links with trailing slash in Rails 3?
本文介绍了如何在 Rails 3 中生成带有斜杠的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将现有网站从 PHP 移植到 Ruby on Rails 3,我必须保持网址不变.
I'm porting the existing website from PHP to Ruby on Rails 3 and I have to keep the urls unchanged.
我有路线:
get 'companies/' => 'companies#index', :as => :companies
在我的视图文件中:
link_to 'Companies', companies_path
这会生成网址http://website.com/companies"而不是http://website.com/companies/".
and this generates the url "http://website.com/companies" instead of "http://website.com/companies/".
我想要网址末尾的斜线.可能吗?
I want the slash at the end of the url. Is it possible?
推荐答案
您可以将此添加到您的 application.rb 中:
You can add this to your application.rb:
config.action_controller.default_url_options = { :trailing_slash => true }
这样所有的路由都会自动生成一个尾部斜杠,无需修改项目中的每个链接.
This way all routes will be generated with a trailing slash automatically, with no need to modify each link in your project.
这篇关于如何在 Rails 3 中生成带有斜杠的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文