加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 为URL添加扩展:Rails

发布时间:2020-12-16 23:11:47 所属栏目:百科 来源:网络整理
导读:我在rails应用程序中设置了一些link_to xml视图.网址如何显示.xml扩展名? Need it to appear as:http://localhost:3000/test/1-testing.xmlCurrently it appears as:http://localhost:3000/test/1-testing 解决方法 在Rails 3中,假设您的路径是foo_path,那
我在rails应用程序中设置了一些link_to xml视图.网址如何显示.xml扩展名?
Need it to appear as:
http://localhost:3000/test/1-testing.xml

Currently it appears as:
http://localhost:3000/test/1-testing

解决方法

在Rails 3中,假设您的路径是foo_path,那么您需要:
foo_path(:format=>:xml)

在link_to中,您可以这样做

link_to "link text",foo_path(:format => :xml)

还有更多选择:

link_to "link text",foo_path(:format => :xml),:id=>"foo_id",:class=>"foo_class"

(这个问题很老了,但我想我会回答帮助那些通过Google找到这个问题的人,就像我做的那样.)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读