I asked this during the Burton Group telebriefing, but Dave Thomas''s usage/explanation went right through me: How do folks use Rails to serve static, non-active record-backed content? For example, our current (lame) site is done using the Why/Jamis model of textile files glued together with YAML. I''d like to get this mostly static part into Rails so that I can begin experimenting with other, database-backed parts of the site. BTW: for our very low traffic site, I am content to completely ignore caching at the moment -- on-the-fly generation from textile files would be a fine starting point. Thanks, -- Bil http://fun3d.larc.nasa.gov
On Oct 5, 2005, at 11:23 AM, Bil Kleb wrote:> <snip> > BTW: for our very low traffic site, I am content > to completely ignore caching at the moment -- on-the-fly > generation from textile files would be a fine > starting point. > > Thanks, > -- > Bil > http://fun3d.larc.nasa.gov > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >Hey Bill- One way to do this is to just have an empty action in your controller for every static page you want. This way if you decide to add dynamic content to these pages, it is already framed out for you. Example: class StatictController < ApplicationController caches_page : another_static, : static_page def static_page end def another_static end end Now just create the .rhtml files : static_page.rhtml and another_static.rhtml in the app/views/static/ directory and put whatever static content you want in these files. Now turn on page caching with caches_page : another_static, : static_page and these files will be built once and then put into your public folder as static html files and will be served by your webserver directly without going through rails. Another simpler way is to just put static .html files in your public directory. You can still call them in the browser without the .html extension because the rails config in the webserver will always look for pages in public with an html extension before it will send it to rails to dispatch. HTH- -Ezra Zygmuntowicz Yakima Herald-Republic WebMaster http://yakimaherald.com 509-577-7732 ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org
On 5-okt-2005, at 21:16, Ezra Zygmuntowicz wrote:>> > > Hey Bill- > One way to do this is to just have an empty action in your > controller for every static page you want. This way if you decide > to add dynamic content to these pages, it is already framed out for > you. > > Example: > > class StatictController < ApplicationController > > caches_page : another_static, : static_page > > def static_page > end > > def another_static > end > > endEven easier. def self.static_action(*action_symbols) action_symbols.each do |action_symbol| eval "def #{action_symbol}; end" eval "caches_page :#{action_symbol}" end end The in your controller, batch style: controller MyController static_action :contact, :about, :signup, :foo end You can of course make it do some nice stuff inside the created methods - like rendering the templates which _actually_ sit inside your web root (but this is quite insecure). I hold 2 separated template trees for a CMS-type job I made recently: /public --/static #this is where views for "public" pages live, HTML designers edit them when needed and you can add dynamicityas desired /app --/views #this is where backend views are stored - miles and miles of Ajax lines, helper calls everywhere. -- Julian "Julik" Tarkhanov
Ezra Zygmuntowicz wrote:> > Now just create the .rhtml files : static_page.rhtml and > another_static.rhtml in the app/views/static/ directory and put > whatever static content you want in these files. > > [..] > > Another simpler way is to just put static .html files in your > public directory.In this case, my static files are Textile, so I''d need to textilize them somehow before rendering? What''s suggested path through Rails for this? Chad pointed me at a textilize helper method at one point. Is there a "How to" somewhere for this? Regards, -- Bil http://fun3d.larc.nasa.gov
Bil Kleb <Bil.Kleb-NSQ8wuThN14@public.gmane.org> writes:> How do folks use Rails to serve static, non-active > record-backed content?,----[ app/controller/pages_controller.rb ] | class PagesController < ApplicationController | | private | | def method_missing(action) | render :action => action.to_s | end | end `---- Then in app/views/pages just add files like foo.rhtml, bar.rhtml, etc. The url for them would be http://mydomain.dom/pages/foo and http://mydomain.dom/pages/bar. The plus is that you can put ERB in them for some simple generated content. Of course, any files you put in public will be served up as static pages. -- Doug Alcorn - http://lathi.net/RubyOnRailsDeveloper doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org