0

I am implementing an html template for a Contact us page in my app. I am wondering if I can somehow pass a link for that page, which will have no behaviour, without having to generate a new controller which seems to be not possible. I tried to place the template in the public folder and then pass a link to /public/contact, being the template contact.html.erb, but rails returns a uninitialised controller routing error.

here is what I have set in the routes.rb file

get 'public/contact'

and this is the application.html.erb that carries my link to that

   </div>
<ul>
  <li><a href="http://localhost:3000">HOME</a></li>
  <li><a href="http://localhost:3000/info/news">NEWS</a></li>
  <li><a href="http://localhost:3000/info/faq">FAQ</a></li>
  <li><a href="http://localhost:3000/public/contact">CONTACT US</a></li>
</ul>

Notice that we have also the path info/news and info/faq

I had generated a controller info to handle all these static pages. I would just like to know if this a good practice or should I use other drier way to implement this?

4

2 回答 2

0

为什么你需要为一个请求生成一个新的控制器。推荐的方法是在你的公共/实用控制器中添加一个新的操作,并带有一个获取请求来展示我们。例如:match '/about' => 'pages#about' 这很好,因为您可以缓存页面以提高性能,也可以使其动态(html.erb)

或者

假设静态文件(仅 html)在public文件夹中,直接添加target=_blank一个锚标记以使用属性在新页面中打开它。

<%= link_to "About Us", "/about_us.html" ,:target=>"_blank"%>
于 2015-01-13T12:40:00.813 回答
0

实际上,为您的静态页面设置一个控制器也是一个好方法,您实际上可以为页面生成一个控制器来处理静态页面,例如 about、contact 等 rails 生成控制器页面联系 about

您只需在
localhost:3000/pages/contact 中访问它

然后您的视图将位于app/views/pages/contact.html.erb

routes.rb 获取“页面/联系人”获取“页面/关于”

于 2015-01-13T10:36:14.960 回答