Quite new to Ruby on Rails and I am stuck on probably an easy task. Basically I am working on a colleague’s app and need to add an additional page that shows users how the app works. I have already written the HTML and styles. I just don’t know how to exactly add it to Rails and configure the routes properly. Any help would be appreciated!
Share
First make sure that your colleague did not already create a controller to handle static pages. Look under
app/controllersfor controllers titled anything similar todirectories_controllerorpages_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
PagesControllerthat 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:Then you’ll want to create a new folder under
app/viewstitledpages, and you can add your static page there (app/views/pages) with a.erbextension. Using a.erbwill allow your new page to use the default layout.Finally, you’ll need to add this controller to
routes.rbin(config/routes.rb)to tell rails where to look for the/helppage: