简体   繁体   中英

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. 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.

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'

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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