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

时间:2022-11-11 22:44:41

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. How do I create this and where does the file live?

我对Rails很新,所以这对大多数人来说可能很容易,但我想添加一个只有一些静态信息和回家的链接的新页面。如何创建此文件以及文件的位置?

Any help would be great! Thank you.

任何帮助都会很棒!谢谢。

2 个解决方案

#1


2  

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的控制器,其中有一个关于它的视图,在views / home / about.html.erb中有相应的视图,你可以编辑它。

#2


1  

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.

基本上只是创建一个路径,就像你想要在控制器上定义的任何新动作一样。它可以在任何控制器上,所有更改都是您将其路由到的位置,您可以在其中定义控制器操作以及放置视图的位置。

#1


2  

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的控制器,其中有一个关于它的视图,在views / home / about.html.erb中有相应的视图,你可以编辑它。

#2


1  

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.

基本上只是创建一个路径,就像你想要在控制器上定义的任何新动作一样。它可以在任何控制器上,所有更改都是您将其路由到的位置,您可以在其中定义控制器操作以及放置视图的位置。