RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

Quick and easy Static Pages in Rails

Comments

Here I thought this is what /public was for…silly me

Pages in /public can’t access your default layouts, can’t have links to the other pages in your site without hard-coding, can’t have dynamic content - “Hi Anonymous Critic. Welcome back to my kewl site!” - and can’t be a custom 404 page - “The page you requested /no/such/page doesn’t exist.”

But the author should have stated these obvious justifications.

Can you put erb templates in /public?

Hi Mom, Sure you could put them in /public, but they would not be processed by rails. They would be downloaded by your webserver untouched.

Ray hit the point spot on and I should have mentioned it in my post, the purpose was that I wanted to render the content inside the standard site layout.

Also, some “static” pages might have some very minor text customizations depending on the person viewing the page.

What is the performance difference between “rendering” (mostly) static erb pages and keeping the files in the /public folder?

Arthur Gunn

That is what I thought. I was just confused by AnonymousCritic’s suggestion for using /public. So it sounds like AnonymousCritic is the confused one.

Adelevie, the difference is negligible as the pages are so light anyway. When requested the full full Rails stack is used rather than just the web server to serve the page. If you are concerned about performance then use caches_page method in the StaticPages controller, or if your application layout has user specific components in the design then use caches_action.

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in