Forum: Ruby on Rails render_to_string troubles

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F719c6cb34bd5b691c12b373b7244b4d?d=identicon&s=25 Dorian Mcfarland (tachekent)
on 2006-03-27 19:17
(Received via mailing list)
Hi,
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:

#site.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
      rebuild_page(options)
    end

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
    expire_page(options)

    # 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
      }
    end
    page = render_to_string(options)

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

  end


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
wrong?

dorian
This topic is locked and can not be replied to.