First make sure that your colleague did not already create a controller to handle static pages. Look under app/controllers
for controllers titled anything similar to directories_controller
or pages_controller
, etc. If he/she has, follow the pattern your colleague already set up (you might want to ask him/her for guidance at that point). If there is not static pages controller like that, then follow the advice below.
You can create a controller named something like PagesController
that defines methods that match a route. For instance, your additional page might be called “help”, in which case you can define a controller like so:
class PagesController < ActionController::Base
def help
# put any code here that you need
# (although for a static view you probably won't have any)
end
end
Then you’ll want to create a new folder under app/views
titled pages
, and you can add your static page there (app/views/pages) with a .erb
extension. Using a .erb
will allow your new page to use the default layout.
Finally, you’ll need to add this controller to routes.rb
in (config/routes.rb)
to tell rails where to look for the /help
page:
match "https://stackoverflow.com/help" => 'pages#help'