saving html from ruby on rails output to a variable -


i have ruby on rails website. page dynamically loaded , generated using ruby , rails. however, i'd generate static .html page ease server rather calling rails page every time.

in php know how capture output buffer using ob_start() , ob_get_contents() outputted text.

how capture output rails page variable?

edit: reason want can save page .html use on other machines. generate html using ruby , distribute others in format can view.

you should use rails caching achieve result. achieves ends looking for.

alternatively, can render_to_string , output result using render:

 #ticket_controller.rb  def ticketcontroller < applicationcontroller     def show_ticket      @ticket = ticket.find(params[:id])       res = render_to_string :action => :show_ticket      #... cache result-- may want adjust path based on needs      #this similar rails caching      #finally, should note rails servers serve files      # /public directory without ever invoking rails proper       file.open("#{rails_root}/public/#{params[:action]}.html", 'w') {|f| f.write(res) }      # or .. file.open("#{rails_root}/public/#{params[:controller]}/#{params[:action]}/#{params[:id]}.html", 'w') {|f| f.write(res) }      # or .. file.open("#{rails_root}/snapshots/#{params[:controller]}/#{params[:action]}/#{params[:id]}.html", 'w') {|f| f.write(res) }      render :text => res    end  end 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -