简体   繁体   English

如何在我的Ruby on Rails网站上添加新的信息页面

[英]How to add a new information page to my Ruby on Rails site

I'm very new to Rails so this is probably quite easy for most but I want to add a new page with simply some static information and a link back home. 我对Rails还是很陌生,所以对大多数人来说这可能很容易,但是我想添加一个新页面,其中仅包含一些静态信息和返回首页的链接。 How do I create this and where does the file live? 如何创建此文件以及该文件在何处?

Any help would be great! 任何帮助将是巨大的! Thank you. 谢谢。

Just create a controller with an action for your static page. 只需为您的静态页面创建一个带有动作的控制器即可。 For example 例如

rails g controller home about

will generate a controller named HomeController with an action about that has a corresponding view in views/home/about.html.erb which you can edit. 会生成一个名为HomeController的控制器,该控制器具有一个about该操作的操作,该操作在views/home/about.html.erb中具有一个相应的视图,您可以对其进行编辑。

In your routes: 在您的路线中:

get 'my_static_info_page' to: 'application#my_static_info_page'

In your controller: 在您的控制器中:

class ApplicationController < ApplicationController::Base

  def my_static_info_page
  end

end

Then create a view under 'app/views/my_static_info_page.html.erb' 然后在“ app / views / my_static_info_page.html.erb”下创建一个视图

Essentially just create a route as you would for any new action you want to define on a controller. 本质上,只需为要在控制器上定义的任何新操作创建一条路由即可。 It can be on any controller, all that changes is where you route it to, where you define the controller action and where you put the view. 它可以在任何控制器上,所有更改都是将其路由到的位置,定义控制器动作的位置以及放置视图的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM