本文介绍了Link_to 用于静态页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个基于论坛的网站,我想在我的页脚中添加一些链接,例如更多关于徽章"或如何提问".嗯,它们是静态页面,所以我真的不想通过控制器去那些页面.例如,我想使用 link_to 或其他可能的标签查看 views/static_pages/badges.html.erb.

I have made a forum-based website, I want to add a few links to my footer like "more about badges" or "how to ask questions". Well, they are static pages so I really don't want to go through controller to go to those pages. For example, I'd like to view views/static_pages/badges.html.erb using link_to or other possible tag.

如何直接进入视图中的某个页面?

How can I go directly to some page in my views?

推荐答案

对于静态页面,您应该查看 high_voltage 宝石.安装后,它将在您的视图目录中创建一个文件夹 pages,并生成一个名为 page_path 的路由方法.例如,如果您创建一个静态页面 pages/static,那么您可以在视图中通过 page_path('static') 引用它.

For static pages you should check out high_voltage gem. Once it's installed, it'll make a folder pages inside your view directory and it'll generate a named route method of page_path. For example, if you create a static page pages/static then you can refer it to by page_path('static') in your views.

如果您不想使用任何 gem,那么我建议您查看 这个问题

If you don't want to use any gem then I'll suggest checking out this question

这篇关于Link_to 用于静态页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 15:08