2006-03-09

one of the most amazing frameworks for dynamic content.. and what’s my problem? i cant figure out where the hell the best place is to place static content.

my first thought was “sure i could just dump a file in /app/views”. seems like a reasonable solution.. but of course rails won’t route that correctly.

so the next solution is to put it there or somewhere else and map it using /config/routes.rb

yeah that could work too..

i definitely wanted it to inherit the layout of all the other pages though and that was managed by the controllers.. so -
easiest thing to do though is to just dump it in a controller.. so for example my file was an faq so i dumped it in

/app/views/mycontroller/faq.rhtml

you dont have to create a placeholder or anything like that.. like


def faq
end

in your “mycontroller” controller.. just drop the file in and go to it in your browser
localhost:3000/mycontroller/faq

if you want it to appear outside the controller i guess the best bet is to just use routes.rb.

4 Responses to “Static pages and content in Ruby on Rails”

  1. physio Says:

    Thanks for posting this. I was wondering what to do myself. Have your thoughts changed on this topic since you posted?

  2. Gabe Says:

    This is how I do it:

    http://darwinweb.net/article/Routing_Nested_Static_Content_In_Rails

    I’ve recently upgraded it to support automatic references to index.rhtml on subfolders of content/

  3. Harlan Iverson Says:

    I was searching for an answer to this on Google and happened across this article; funnies. The last hit I found suggested using method_missing so that you don’t have to create a method for each static page.

    http://lists.rubyonrails.org/pipermail/rails/2005-March/004449.html

  4. Waqas Says:

    Thanks, but following is definitely the best method to handle static pages.

    http://blog.daviddollar.org/2009/08/22/static-pages-in-rails.html

Leave a Reply


I've left the country and this site is just an archive! Check out my trip blog!