Adding content to static files

I have several static files(pages), which are basically copies of my
website pages source code, with the content changed.
These files support my website, (keeping the same format) in various
ways.
For example the menu part is:-

    etc etc. until

Unfortunately every month or so my menu bar changes and I have to
update each static file manually.
As each of my static files have the same menu.
Is it possible to have one menu file which can be updated and have the
static files load them automatically.
I plan to have several more static files. So this would be a great
help if someone can suggest how to accomplish this.

On 26 November 2010 12:04, MDM [email protected] wrote:

    I plan to have several more static files. So this would be a great help if someone can suggest how to accomplish this.

I would recommend providing a ‘main’ controller (or whatever you want
to call it) that just serves up the effectively static pages.
Initially you can just put the html straight into each page.html.erb
and render them specifying no layout. Then you can refactor them and
use the rails capabilities of partials, helpers and so on to put your
re-usable menu into a partial to make life easy.

Colin

Thanks for that which gives me an idea to create one controller and
import each static page content into it somehow. Then I would not have
to even worry about updating the menu at all.

Sounds to me that you need to use layouts for your application.
By doing this, you need to only update one file and it’ll be reflected
everywhere on your site.

L


www.saffie.ca

Though I would assert that Colin’s suggestion is the better, you might
also consider using a static site generator for your static content:
something like nanoc or jekyll.

I ended up creating one controller without a model. (rails g
controller staticpages)
I then created a layout file which imported the individual changes to
the layout, via a “yield” tied to a “content_for” in the view
files(static files(pages) in the “view of staticpages”(for example
abbreviations, aboutthissite etc etc).
The rest of the static file loaded with the usual “yield” to the
layout. Works a treat. No more updating the menu bar all done
automatically.
To get to the correct static file I created a route using:-

match ‘static/:static_page_name’=> ‘staticpages#show’ (or in rails
2.x:-
map.connect ‘static/:static_page_name’, :controller=>
“staticpages”, :action=> “show”

“static_page_name” variable accepted anything after “/static/” in the
url and passed it to the controller “staticpages” in which I set up a
show action containing:-

def show
@static_page_name = params[:static_page_name]
allowed_pages = %w(abbreviations aboutthissite etc, etc,)
if allowed_pages.include?(@static_page_name)
render @static_page_name
else
redirect_to ‘/’ #redirects to
homepage if link does not exists
end
end

I then only had to change the links in the website. (e.g.<%= link_to "
About This Site ", ‘/static/aboutthissite’ %>)

and viola! its all working.