Forum: Ruby on Rails render_to_string troubles

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Dorian M. (Guest)
on 2006-03-27 21:17
(Received via mailing list)
I'm trying to build a simple mechanism for pre-caching a bunch of files
by iterating over a hash of options from within a controller:


    for options in [
      { :controller => "site", :action => "welcome" },
      { :controller => "site", :action => "about" },
      { :controller => "site", :action => "contact" },
      { :controller => "site", :action => "funding" },
      { :controller => "site", :action => "funding", :params => { 'page'
=> "proposal.html" } },
      { :controller => "site", :action => "funding", :params => { 'page'
=> "submissions.html" } },
      { :controller => "site", :action => "funding", :params => { 'page'
=> "production.html" } }
    ] do

with the following in the application.rb controller:

  # handle all regeneration of pages - available to all controllers
  def rebuild_page(options, path = nil)

    # get rid of the existing one

    # pull the page in as a string
    # set page parameters first:
    if options.has_key?(:params)
      options[:params].each_pair {
        |key, value|
        @params[key] = value
    page = render_to_string(options)

    # write the rendered content to the right place
    cache_page(page, options)


I can see the parameters have been set, but somehow the 'page' parameter
never gets processed by the funding action, so I end up with a 4 pages
that all have the same content (the simple funding page). My 'funding'
action also has a bunch of other @vars which seem to not be available
when rendering the template.

I presumed that the render_to_string method would process the :action
with all available parameters, but I can't make it do so - am I doing it

This topic is locked and can not be replied to.