2

I wanted to make a simple page for a footer of a site discussing the team of the project. Such a page usually just has information and nothing too fancy.

I didn't make a route for it, and just basically saved it as team.html.rb in the folder: /app/views/team.html.rb

I am not sure whether that is the right place for such a file to be saved to. Where is the best place for such a one-off file?

Also, do I still need to make a route and a controller for this, or can I just skip those for such a simple page?

Thanks!!

GeekedOut
  • 16,905
  • 37
  • 107
  • 185

3 Answers3

2

I'm using a controller to deliver static pages.

Here's a link to a similar question:

How to do static content in Rails?

What you can do also is put a static html file into the 'public' folder and refer to it like this:

http://localhost:3000/name-of-static-file

Community
  • 1
  • 1
mkro
  • 1,902
  • 14
  • 15
1

I don't think that will work because Rails expects all requests to go through a controller. The simplest thing would be to do something like this at the end of your routes.rb:

match "/:action" => "pages"

Then in app/views/pages you can put your team.html.erb. You also will probably need at least a blank controller in app/views/pages_controller.rb:

class PagesController < ApplicationController
end

The nice thing about this is if you happen to need some dynamic content for one of the "static" pages you can just define a controller method to load it.

If this seems like overkill for your site, you might want a lighter framework like Sinatra

gtd
  • 16,956
  • 6
  • 49
  • 65
  • Probably what would work best for me is to define a StaticPageController and be able to correctly redirect the diff static page requests that come in. How could I do that? – GeekedOut May 24 '11 at 22:28
1

routes point to controller actions, not views.

a request to /team would (iirc) point to application#team. If that action doesn't exist, you will get an error. If you DO have that action defined (with a call to render, it will look in /app/views/application for a file called team.html[.erb|.json|.etc]

As the related thread points out, thoughtbot's high_voltage gem is great for a base of serving static pages.

colinross
  • 2,075
  • 13
  • 10