简体   繁体   中英

how do you organize static pages in your rails projects?

There are always some static pages such as About(about.html), Contacts(contacts.html) and other. In some tutorials authors create a special controller named "site" and define actions 'about', 'contacts' which just render static pages and allow using link_to in other erb pages. Other authors just create static html pages and use old-good About or something like that. Which method is better(if any is) and why choosing one over another?

I don't like accessing static resources directly from the URL bar--too often they end up becoming not static at some point, breaking links, and causing app-wide linking updates. Not always a big deal, since things like that are usually isolated, but... not always, and finding them when they're not can be a pain.

I just don't see a good reason for isolating them as static resources, they usually use the same layout as the rest of the site, you may want to add behavior later, etc.

Serve the static assets directly through Nginx or Apache -- it's much faster this way.

See: http://blog.joeygeiger.com/2011/06/07/serving-assets-in-rails-3-1-with-nginx/

Ok so you know the two main answers (there are some variations for the first). Which one to use is opt to you. If you just need some little ruby go with the static controller (it can be named whatever you want). If you are not going to use any of the rails/ruby goodies then stay away from rails and serve those pages with apache/nginx.

Update : Read the second paragraph from Dave Newton, sometimes using the rails stack just to keep your layout consistent makes a lot of sense. Make sure to use page caching.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM